# HG changeset patch # User jbe # Date 1427155712 -3600 # Node ID d8480a60a07dae0ad53741ed97fc55689b72fdcf # Parent ae6e889fe2646c4b76ad3cc55c991f5749117bc4 Discard process after error diff -r ae6e889fe264 -r d8480a60a07d framework/bin/mcp.lua --- a/framework/bin/mcp.lua Tue Mar 24 00:12:49 2015 +0100 +++ b/framework/bin/mcp.lua Tue Mar 24 01:08:32 2015 +0100 @@ -304,7 +304,7 @@ local request_count = 0 local function inner_handler(http_request) request.initialize() - request.handler(http_request, request_count >= max_requests_per_fork) + return request.handler(http_request, request_count >= max_requests_per_fork) end local outer_handler = http.generate_handler(inner_handler, args.http_options) args.prepare = postfork_init @@ -314,7 +314,10 @@ request.initialize() interval_handlers[socket.interval]() else - outer_handler(socket) + local success = outer_handler(socket) + if not success then + return false + end end return request_count < min_requests_per_fork end diff -r ae6e889fe264 -r d8480a60a07d framework/env/request/handler.lua --- a/framework/env/request/handler.lua Tue Mar 24 00:12:49 2015 +0100 +++ b/framework/env/request/handler.lua Tue Mar 24 01:08:32 2015 +0100 @@ -1,4 +1,5 @@ --[[-- +success = -- false if an error occurred, true otherwise request.handler( http_request, -- HTTP request object close -- boolean indicating whether the server should announce to close the connection @@ -19,6 +20,7 @@ end function request.handler(http_request, close) + local close_sent = false request._http_request = http_request local path = http_request.path if path then @@ -44,6 +46,7 @@ if close then request.add_header("Connection", "close") + close_sent = true end local success, error_info = xpcall( @@ -55,26 +58,28 @@ if request.get_404_route() then request.set_status("404 Not Found") request.forward(request.get_404_route()) - return else error('Could not open static file "' .. request._route.static .. '": ' .. errmsg) end + else + local d = assert(f:read("*a")) + f:close() + slot.put_into("data", d) + local filename_extension = string.match(request._route.static, "%.([^.]+)$") + slot.set_layout(nil, request._mime_types[filename_extension] or "application/octet-stream") + request.allow_caching() + return end - local d = assert(f:read("*a")) - f:close() - slot.put_into("data", d) - local filename_extension = string.match(request._route.static, "%.([^.]+)$") - slot.set_layout(nil, request._mime_types[filename_extension] or "application/octet-stream") - request.allow_caching() - return end -- restore slots if coming from http redirect - local tempstore_value = http_request.get_params["_tempstore"] - if tempstore_value then - trace.restore_slots{} - local blob = tempstore.pop(tempstore_value) - if blob then slot.restore_all(blob) end + do + local tempstore_value = http_request.get_params["_tempstore"] + if tempstore_value then + trace.restore_slots{} + local blob = tempstore.pop(tempstore_value) + if blob then slot.restore_all(blob) end + end end if request.get_action() then @@ -203,6 +208,9 @@ if not request._status then request._status = "500 Internal Server Error" end + if not close_sent then + request.add_header("Connection", "close") + end slot.set_layout('system_error') slot.select('system_error', function() if getmetatable(errobj) == mondelefant.errorobject_metatable then @@ -254,4 +262,6 @@ http_request:finish() end + return success + end