aboutsummaryrefslogtreecommitdiffstats
path: root/net/http
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2019-10-12 18:27:02 +0200
committerKim Alvefur <zash@zash.se>2019-10-12 18:27:02 +0200
commit89a6f8d8c108bdf633d7d6589c260de833c56bf5 (patch)
tree638386430c8cfb521ffcab157fa5ec5572b77065 /net/http
parent6fd6ad9958fb23a8956a21810113c5da99a40b6a (diff)
downloadprosody-89a6f8d8c108bdf633d7d6589c260de833c56bf5.tar.gz
prosody-89a6f8d8c108bdf633d7d6589c260de833c56bf5.zip
net.http.server: Ensure HEAD requests are sent with empty body
Diffstat (limited to 'net/http')
-rw-r--r--net/http/server.lua16
1 files changed, 16 insertions, 0 deletions
diff --git a/net/http/server.lua b/net/http/server.lua
index 9b63d516..47680455 100644
--- a/net/http/server.lua
+++ b/net/http/server.lua
@@ -194,8 +194,11 @@ function handle_request(conn, request, finish_cb)
response_conn_header = httpversion == "1.1" and "close" or nil
end
+ local is_head_request = request.method == "HEAD";
+
local response = {
request = request;
+ is_head_request = is_head_request;
status_code = 200;
headers = { date = date_header, connection = response_conn_header };
persistent = persistent;
@@ -291,16 +294,29 @@ local function prepare_header(response)
return output;
end
_M.prepare_header = prepare_header;
+function _M.send_head_response(response)
+ if response.finished then return; end
+ local output = prepare_header(response);
+ response.conn:write(t_concat(output));
+ response:done();
+end
function _M.send_response(response, body)
if response.finished then return; end
body = body or response.body or "";
response.headers.content_length = #body;
+ if response.is_head_request then
+ return _M.send_head_response(response)
+ end
local output = prepare_header(response);
t_insert(output, body);
response.conn:write(t_concat(output));
response:done();
end
function _M.send_file(response, f)
+ if response.is_head_request then
+ if f.close then f:close(); end
+ return _M.send_head_response(response);
+ end
if response.finished then return; end
local chunked = not response.headers.content_length;
if chunked then response.headers.transfer_encoding = "chunked"; end