webmcp
changeset 327:d8480a60a07d
Discard process after error
author | jbe |
---|---|
date | Tue Mar 24 01:08:32 2015 +0100 (2015-03-24) |
parents | ae6e889fe264 |
children | 04b0687130d8 |
files | framework/bin/mcp.lua framework/env/request/handler.lua |
line diff
1.1 --- a/framework/bin/mcp.lua Tue Mar 24 00:12:49 2015 +0100 1.2 +++ b/framework/bin/mcp.lua Tue Mar 24 01:08:32 2015 +0100 1.3 @@ -304,7 +304,7 @@ 1.4 local request_count = 0 1.5 local function inner_handler(http_request) 1.6 request.initialize() 1.7 - request.handler(http_request, request_count >= max_requests_per_fork) 1.8 + return request.handler(http_request, request_count >= max_requests_per_fork) 1.9 end 1.10 local outer_handler = http.generate_handler(inner_handler, args.http_options) 1.11 args.prepare = postfork_init 1.12 @@ -314,7 +314,10 @@ 1.13 request.initialize() 1.14 interval_handlers[socket.interval]() 1.15 else 1.16 - outer_handler(socket) 1.17 + local success = outer_handler(socket) 1.18 + if not success then 1.19 + return false 1.20 + end 1.21 end 1.22 return request_count < min_requests_per_fork 1.23 end
2.1 --- a/framework/env/request/handler.lua Tue Mar 24 00:12:49 2015 +0100 2.2 +++ b/framework/env/request/handler.lua Tue Mar 24 01:08:32 2015 +0100 2.3 @@ -1,4 +1,5 @@ 2.4 --[[-- 2.5 +success = -- false if an error occurred, true otherwise 2.6 request.handler( 2.7 http_request, -- HTTP request object 2.8 close -- boolean indicating whether the server should announce to close the connection 2.9 @@ -19,6 +20,7 @@ 2.10 end 2.11 2.12 function request.handler(http_request, close) 2.13 + local close_sent = false 2.14 request._http_request = http_request 2.15 local path = http_request.path 2.16 if path then 2.17 @@ -44,6 +46,7 @@ 2.18 2.19 if close then 2.20 request.add_header("Connection", "close") 2.21 + close_sent = true 2.22 end 2.23 2.24 local success, error_info = xpcall( 2.25 @@ -55,26 +58,28 @@ 2.26 if request.get_404_route() then 2.27 request.set_status("404 Not Found") 2.28 request.forward(request.get_404_route()) 2.29 - return 2.30 else 2.31 error('Could not open static file "' .. request._route.static .. '": ' .. errmsg) 2.32 end 2.33 + else 2.34 + local d = assert(f:read("*a")) 2.35 + f:close() 2.36 + slot.put_into("data", d) 2.37 + local filename_extension = string.match(request._route.static, "%.([^.]+)$") 2.38 + slot.set_layout(nil, request._mime_types[filename_extension] or "application/octet-stream") 2.39 + request.allow_caching() 2.40 + return 2.41 end 2.42 - local d = assert(f:read("*a")) 2.43 - f:close() 2.44 - slot.put_into("data", d) 2.45 - local filename_extension = string.match(request._route.static, "%.([^.]+)$") 2.46 - slot.set_layout(nil, request._mime_types[filename_extension] or "application/octet-stream") 2.47 - request.allow_caching() 2.48 - return 2.49 end 2.50 2.51 -- restore slots if coming from http redirect 2.52 - local tempstore_value = http_request.get_params["_tempstore"] 2.53 - if tempstore_value then 2.54 - trace.restore_slots{} 2.55 - local blob = tempstore.pop(tempstore_value) 2.56 - if blob then slot.restore_all(blob) end 2.57 + do 2.58 + local tempstore_value = http_request.get_params["_tempstore"] 2.59 + if tempstore_value then 2.60 + trace.restore_slots{} 2.61 + local blob = tempstore.pop(tempstore_value) 2.62 + if blob then slot.restore_all(blob) end 2.63 + end 2.64 end 2.65 2.66 if request.get_action() then 2.67 @@ -203,6 +208,9 @@ 2.68 if not request._status then 2.69 request._status = "500 Internal Server Error" 2.70 end 2.71 + if not close_sent then 2.72 + request.add_header("Connection", "close") 2.73 + end 2.74 slot.set_layout('system_error') 2.75 slot.select('system_error', function() 2.76 if getmetatable(errobj) == mondelefant.errorobject_metatable then 2.77 @@ -254,4 +262,6 @@ 2.78 http_request:finish() 2.79 end 2.80 2.81 + return success 2.82 + 2.83 end