diff options
author | Kim Alvefur <zash@zash.se> | 2021-04-24 10:50:24 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2021-04-24 10:50:24 +0200 |
commit | 0175ab04cc75c28393095cd0cb717abe1fcc1271 (patch) | |
tree | fae61d50be1141845431c1ffd35bcb1c839387fd /net/http | |
parent | f18e33228d3ca99be0c45fc1084ccd4f27d3ef87 (diff) | |
download | prosody-0175ab04cc75c28393095cd0cb717abe1fcc1271.tar.gz prosody-0175ab04cc75c28393095cd0cb717abe1fcc1271.zip |
net.http.server: Split out method for sending only the header
Makes it easier to reuse, e.g. for SSE or websockets or other custom
responses.
Diffstat (limited to 'net/http')
-rw-r--r-- | net/http/server.lua | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/net/http/server.lua b/net/http/server.lua index ab71dbc9..97e15e42 100644 --- a/net/http/server.lua +++ b/net/http/server.lua @@ -256,6 +256,7 @@ function handle_request(conn, request, finish_cb) persistent = persistent; conn = conn; send = _M.send_response; + write_headers = _M.write_headers; send_file = _M.send_file; done = _M.finish_response; finish_cb = finish_cb; @@ -329,10 +330,14 @@ local function prepare_header(response) return output; end _M.prepare_header = prepare_header; -function _M.send_head_response(response) +function _M.write_headers(response) if response.finished then return; end local output = prepare_header(response); response.conn:write(t_concat(output)); +end +function _M.send_head_response(response) + if response.finished then return; end + _M.write_headers(response); response:done(); end function _M.send_response(response, body) @@ -381,7 +386,7 @@ function _M.send_file(response, f) return response:done(); end end - response.conn:write(t_concat(prepare_header(response))); + _M.write_headers(response); return true; end function _M.finish_response(response) |