webmcp
diff framework/env/request/handler.lua @ 327:d8480a60a07d
Discard process after error
author | jbe |
---|---|
date | Tue Mar 24 01:08:32 2015 +0100 (2015-03-24) |
parents | e3e2a03f75b2 |
children | 04b0687130d8 |
line diff
1.1 --- a/framework/env/request/handler.lua Tue Mar 24 00:12:49 2015 +0100 1.2 +++ b/framework/env/request/handler.lua Tue Mar 24 01:08:32 2015 +0100 1.3 @@ -1,4 +1,5 @@ 1.4 --[[-- 1.5 +success = -- false if an error occurred, true otherwise 1.6 request.handler( 1.7 http_request, -- HTTP request object 1.8 close -- boolean indicating whether the server should announce to close the connection 1.9 @@ -19,6 +20,7 @@ 1.10 end 1.11 1.12 function request.handler(http_request, close) 1.13 + local close_sent = false 1.14 request._http_request = http_request 1.15 local path = http_request.path 1.16 if path then 1.17 @@ -44,6 +46,7 @@ 1.18 1.19 if close then 1.20 request.add_header("Connection", "close") 1.21 + close_sent = true 1.22 end 1.23 1.24 local success, error_info = xpcall( 1.25 @@ -55,26 +58,28 @@ 1.26 if request.get_404_route() then 1.27 request.set_status("404 Not Found") 1.28 request.forward(request.get_404_route()) 1.29 - return 1.30 else 1.31 error('Could not open static file "' .. request._route.static .. '": ' .. errmsg) 1.32 end 1.33 + else 1.34 + local d = assert(f:read("*a")) 1.35 + f:close() 1.36 + slot.put_into("data", d) 1.37 + local filename_extension = string.match(request._route.static, "%.([^.]+)$") 1.38 + slot.set_layout(nil, request._mime_types[filename_extension] or "application/octet-stream") 1.39 + request.allow_caching() 1.40 + return 1.41 end 1.42 - local d = assert(f:read("*a")) 1.43 - f:close() 1.44 - slot.put_into("data", d) 1.45 - local filename_extension = string.match(request._route.static, "%.([^.]+)$") 1.46 - slot.set_layout(nil, request._mime_types[filename_extension] or "application/octet-stream") 1.47 - request.allow_caching() 1.48 - return 1.49 end 1.50 1.51 -- restore slots if coming from http redirect 1.52 - local tempstore_value = http_request.get_params["_tempstore"] 1.53 - if tempstore_value then 1.54 - trace.restore_slots{} 1.55 - local blob = tempstore.pop(tempstore_value) 1.56 - if blob then slot.restore_all(blob) end 1.57 + do 1.58 + local tempstore_value = http_request.get_params["_tempstore"] 1.59 + if tempstore_value then 1.60 + trace.restore_slots{} 1.61 + local blob = tempstore.pop(tempstore_value) 1.62 + if blob then slot.restore_all(blob) end 1.63 + end 1.64 end 1.65 1.66 if request.get_action() then 1.67 @@ -203,6 +208,9 @@ 1.68 if not request._status then 1.69 request._status = "500 Internal Server Error" 1.70 end 1.71 + if not close_sent then 1.72 + request.add_header("Connection", "close") 1.73 + end 1.74 slot.set_layout('system_error') 1.75 slot.select('system_error', function() 1.76 if getmetatable(errobj) == mondelefant.errorobject_metatable then 1.77 @@ -254,4 +262,6 @@ 1.78 http_request:finish() 1.79 end 1.80 1.81 + return success 1.82 + 1.83 end