moonbridge
diff moonbridge_http.lua @ 7:4d7551c962d5
New method request:send_text_status_response(...) that was previously only available internally as error_response(...) function
author | jbe |
---|---|
date | Thu Jan 29 01:33:00 2015 +0100 (2015-01-29) |
parents | 4b6d7ca25381 |
children | 7e6faff049c3 |
line diff
1.1 --- a/moonbridge_http.lua Wed Jan 14 12:32:11 2015 +0100 1.2 +++ b/moonbridge_http.lua Thu Jan 29 01:33:00 2015 +0100 1.3 @@ -753,6 +753,20 @@ 1.4 read_body_bytes(request_body_content_length, callback) 1.5 end 1.6 input_state = "finished" 1.7 + end, 1.8 + -- helper function to send simple status responses, 1.9 + -- e.g. to send errors for malformed requests, etc.: 1.10 + send_text_status_response = function(status, text) 1.11 + request:send_status(status) 1.12 + request:send_header("Content-Type", "text/plain") 1.13 + if not connection_close_responded then 1.14 + request:send_header("Connection", "close") 1.15 + end 1.16 + request:send_data(status, "\n") 1.17 + if text then 1.18 + request:send_data("\n", text, "\n") 1.19 + end 1.20 + request:finish() 1.21 end 1.22 } 1.23 -- initialize tables for GET params in request object: 1.24 @@ -776,18 +790,11 @@ 1.25 end 1.26 end 1.27 }) 1.28 - -- low level HTTP error response (for malformed requests, etc.): 1.29 - local function error_response(status, text) 1.30 - request:send_status(status) 1.31 - request:send_header("Content-Type", "text/plain") 1.32 - if not connection_close_responded then 1.33 - request:send_header("Connection", "close") 1.34 - end 1.35 - request:send_data(status, "\n") 1.36 - if text then 1.37 - request:send_data("\n", text, "\n") 1.38 - end 1.39 - request:finish() 1.40 + -- wrapper for request:send_text_status_response(...) method to 1.41 + -- send an error status for malformed requests, etc., and to 1.42 + -- return the boolean value of the "survive" variable: 1.43 + local function error_response(...) 1.44 + request:send_text_status_response(...) 1.45 return survive 1.46 end 1.47 -- read and parse request line: