# HG changeset patch # User jbe # Date 1426825857 -3600 # Node ID 8aa38ddcc1b2530c708a59e3b00beeba56e00b46 # Parent b0f5e7955ffd0ec4e0fc2e634ddb7ce4789779f6 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 diff -r b0f5e7955ffd -r 8aa38ddcc1b2 framework/bin/mcp.lua --- a/framework/bin/mcp.lua Tue Mar 17 19:27:58 2015 +0100 +++ b/framework/bin/mcp.lua Fri Mar 20 05:30:57 2015 +0100 @@ -211,17 +211,26 @@ -- invoke moonbridge if WEBMCP_MODE == "listen" then + local http_options = request.get_http_options() + local min_requests_per_connect = http_options.min_requests_per_connect or 90 + local max_requests_per_connect = http_options.max_requests_per_connect or 100 local http = require("moonbridge_http") for i, listener in ipairs(listeners) do + local request_count = 0 + local function inner_handler(request) + request_count = request_count + 1 + request.handler(request, request_count >= max_requests_per_connect) + end + local outer_handler = http.generate_handler(inner_handler, http_options) --listener.prepare = execute.postfork_initializers listener.prepare = function() _G.multirand = require "multirand" execute.postfork_initializers() end - listener.connect = http.generate_handler( - request.handler, - request.get_http_options() - ) + listener.connect = function(socket) + outer_handler(socket) + return request_count < min_requests_per_connect + end listener.finish = execute.finalizers moonbridge_listen(listener) end diff -r b0f5e7955ffd -r 8aa38ddcc1b2 framework/env/request/handler.lua --- a/framework/env/request/handler.lua Tue Mar 17 19:27:58 2015 +0100 +++ b/framework/env/request/handler.lua Fri Mar 20 05:30:57 2015 +0100 @@ -1,6 +1,7 @@ --[[-- request.handler( - request -- HTTP request object + request, -- HTTP request object + close -- boolean indicating whether the server should announce to close the connection ) Called by mcp.lua to process an HTTP request. Performs some initializations, calls request.router(), and handles the request. @@ -18,7 +19,7 @@ end -- TODO: function incomplete yet -function request.handler(http_request) +function request.handler(http_request, close) _G.app = {} -- may be overwritten or modified by request initializers do request._in_progress = true -- NOTE: must be set to true before initializer functions are called @@ -40,6 +41,10 @@ end request._route = request.router() or {} + if close then + request.add_header("Connection", "close") + end + local success, error_info = xpcall( function() @@ -218,7 +223,9 @@ redirect_params.tempstore = tempstore.save(slot_dump) end http_request:send_status("303 See Other") - http_request:send_header("Connection", "close") -- TODO: extend moonbridge + for i, header in ipairs(request._response_headers) do + http_request:send_header(header[1], header[2]) + end http_request:send_header( "Location", encode.url{ @@ -236,7 +243,6 @@ if not success or not redirect_data then http_request:send_status(request._status or "200 OK") - http_request:send_header("Connection", "close") -- TODO: extend moonbridge for i, header in ipairs(request._response_headers) do http_request:send_header(header[1], header[2]) end