Diff

mod_http_upload/mod_http_upload.lua @ 2738:46b29a377bdf

mod_http_upload: Handle HEAD requests in 0.10 when reading body from a file handle
author Kim Alvefur <zash@zash.se>
date Wed, 16 Aug 2017 00:01:14 +0200
parent 2732:b1c5b0c369c2
child 2767:e1edf643fbb1
line wrap: on
line diff
--- a/mod_http_upload/mod_http_upload.lua	Tue Aug 15 21:14:55 2017 +0200
+++ b/mod_http_upload/mod_http_upload.lua	Wed Aug 16 00:01:14 2017 +0200
@@ -256,8 +256,12 @@
 
 	local status_line = "HTTP/"..response.request.httpversion.." "..(response.status or codes[response.status_code]);
 	local headers = response.headers;
-	body = body or response.body or "";
-	headers.content_length = #body;
+	if type(body) == "string" then
+		headers.content_length = #body;
+	elseif io.type(body) == "file" then
+		headers.content_length = body:seek("end");
+		body:close();
+	end
 
 	local output = { status_line };
 	for k,v in pairs(headers) do
@@ -282,6 +286,7 @@
 
 local function serve_head(event, path)
 	event.response.send = send_response_sans_body;
+	event.response.send_file = send_response_sans_body;
 	return serve_uploaded_files(event, path);
 end