webmcp

changeset 264:8aa38ddcc1b2

New configuration options "min_requests_per_connect" and "max_requests_per_connect"; Bugfix: Send headers added with request.add_header(...) also in case of 303 Redirect
author jbe
date Fri Mar 20 05:30:57 2015 +0100 (2015-03-20)
parents b0f5e7955ffd
children a88662f795e0
files framework/bin/mcp.lua framework/env/request/handler.lua
line diff
     1.1 --- a/framework/bin/mcp.lua	Tue Mar 17 19:27:58 2015 +0100
     1.2 +++ b/framework/bin/mcp.lua	Fri Mar 20 05:30:57 2015 +0100
     1.3 @@ -211,17 +211,26 @@
     1.4  
     1.5  -- invoke moonbridge
     1.6  if WEBMCP_MODE == "listen" then
     1.7 +  local http_options = request.get_http_options()
     1.8 +  local min_requests_per_connect = http_options.min_requests_per_connect or 90
     1.9 +  local max_requests_per_connect = http_options.max_requests_per_connect or 100
    1.10    local http = require("moonbridge_http")
    1.11    for i, listener in ipairs(listeners) do
    1.12 +    local request_count = 0
    1.13 +    local function inner_handler(request)
    1.14 +      request_count = request_count + 1
    1.15 +      request.handler(request, request_count >= max_requests_per_connect)
    1.16 +    end
    1.17 +    local outer_handler = http.generate_handler(inner_handler, http_options)
    1.18      --listener.prepare = execute.postfork_initializers
    1.19      listener.prepare = function()
    1.20        _G.multirand = require "multirand"
    1.21        execute.postfork_initializers()
    1.22      end
    1.23 -    listener.connect = http.generate_handler(
    1.24 -      request.handler,
    1.25 -      request.get_http_options()
    1.26 -    )
    1.27 +    listener.connect = function(socket)
    1.28 +      outer_handler(socket)
    1.29 +      return request_count < min_requests_per_connect
    1.30 +    end
    1.31      listener.finish = execute.finalizers
    1.32      moonbridge_listen(listener)
    1.33    end
     2.1 --- a/framework/env/request/handler.lua	Tue Mar 17 19:27:58 2015 +0100
     2.2 +++ b/framework/env/request/handler.lua	Fri Mar 20 05:30:57 2015 +0100
     2.3 @@ -1,6 +1,7 @@
     2.4  --[[--
     2.5  request.handler(
     2.6 -  request         -- HTTP request object
     2.7 +  request,        -- HTTP request object
     2.8 +  close           -- boolean indicating whether the server should announce to close the connection
     2.9  )
    2.10  
    2.11  Called by mcp.lua to process an HTTP request. Performs some initializations, calls request.router(), and handles the request.
    2.12 @@ -18,7 +19,7 @@
    2.13  end
    2.14  
    2.15  -- TODO: function incomplete yet
    2.16 -function request.handler(http_request)
    2.17 +function request.handler(http_request, close)
    2.18    _G.app = {}  -- may be overwritten or modified by request initializers
    2.19    do
    2.20      request._in_progress = true  -- NOTE: must be set to true before initializer functions are called
    2.21 @@ -40,6 +41,10 @@
    2.22    end
    2.23    request._route = request.router() or {}
    2.24  
    2.25 +  if close then
    2.26 +    request.add_header("Connection", "close")
    2.27 +  end
    2.28 +
    2.29    local success, error_info = xpcall(
    2.30      function()
    2.31  
    2.32 @@ -218,7 +223,9 @@
    2.33        redirect_params.tempstore = tempstore.save(slot_dump)
    2.34      end
    2.35      http_request:send_status("303 See Other")
    2.36 -    http_request:send_header("Connection", "close")  -- TODO: extend moonbridge
    2.37 +    for i, header in ipairs(request._response_headers) do
    2.38 +      http_request:send_header(header[1], header[2])
    2.39 +    end
    2.40      http_request:send_header(
    2.41        "Location",
    2.42        encode.url{
    2.43 @@ -236,7 +243,6 @@
    2.44    if not success or not redirect_data then
    2.45  
    2.46      http_request:send_status(request._status or "200 OK")
    2.47 -    http_request:send_header("Connection", "close")  -- TODO: extend moonbridge
    2.48      for i, header in ipairs(request._response_headers) do
    2.49        http_request:send_header(header[1], header[2])
    2.50      end

Impressum / About Us