moonbridge

diff moonbridge_http.lua @ 60:14ef90c46e16

New method request:close_after_finish()
author jbe
date Tue Mar 24 01:51:07 2015 +0100 (2015-03-24)
parents fd0fe0adb203
children 12950c28b73a
line diff
     1.1 --- a/moonbridge_http.lua	Tue Mar 24 00:51:13 2015 +0100
     1.2 +++ b/moonbridge_http.lua	Tue Mar 24 01:51:07 2015 +0100
     1.3 @@ -254,9 +254,9 @@
     1.4          then
     1.5            local error_response_status, errmsg2 = pcall(function()
     1.6              request:defer_reading()  -- don't read request body (because of possibly invalid state)
     1.7 +            request:close_after_finish()  -- send "Connection: close" header
     1.8              request:send_status(status)
     1.9              request:send_header("Content-Type", "text/plain")
    1.10 -            request:send_header("Connection", "close")
    1.11              request:send_data(status, "\n")
    1.12              if text then
    1.13                request:send_data("\n", text, "\n")
    1.14 @@ -444,6 +444,17 @@
    1.15            end
    1.16            assert_output(socket:write(key, ": ", value, "\r\n"))
    1.17          end,
    1.18 +        -- method to announce (and enforce) connection close after sending the response:
    1.19 +        close_after_finish = function()
    1.20 +          assert_not_faulty()
    1.21 +          if
    1.22 +            output_state == "headers_sent" or
    1.23 +            output_state == "finished"
    1.24 +          then
    1.25 +            error("All HTTP headers have already been sent")
    1.26 +          end
    1.27 +          connection_close_requested = true
    1.28 +        end,
    1.29          -- method to finish and flush headers:
    1.30          finish_headers = function()
    1.31            assert_not_faulty()

Impressum / About Us