Mercurial > prosody-modules
comparison 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 |
parents | b1c5b0c369c2 |
children | e1edf643fbb1 |
comparison
equal
deleted
inserted
replaced
2737:f43c77c69a8a | 2738:46b29a377bdf |
---|---|
254 response.finished = true; | 254 response.finished = true; |
255 response.conn._http_open_response = nil; | 255 response.conn._http_open_response = nil; |
256 | 256 |
257 local status_line = "HTTP/"..response.request.httpversion.." "..(response.status or codes[response.status_code]); | 257 local status_line = "HTTP/"..response.request.httpversion.." "..(response.status or codes[response.status_code]); |
258 local headers = response.headers; | 258 local headers = response.headers; |
259 body = body or response.body or ""; | 259 if type(body) == "string" then |
260 headers.content_length = #body; | 260 headers.content_length = #body; |
261 elseif io.type(body) == "file" then | |
262 headers.content_length = body:seek("end"); | |
263 body:close(); | |
264 end | |
261 | 265 |
262 local output = { status_line }; | 266 local output = { status_line }; |
263 for k,v in pairs(headers) do | 267 for k,v in pairs(headers) do |
264 t_insert(output, headerfix[k]..v); | 268 t_insert(output, headerfix[k]..v); |
265 end | 269 end |
280 | 284 |
281 local serve_uploaded_files = http_files.serve(storage_path); | 285 local serve_uploaded_files = http_files.serve(storage_path); |
282 | 286 |
283 local function serve_head(event, path) | 287 local function serve_head(event, path) |
284 event.response.send = send_response_sans_body; | 288 event.response.send = send_response_sans_body; |
289 event.response.send_file = send_response_sans_body; | |
285 return serve_uploaded_files(event, path); | 290 return serve_uploaded_files(event, path); |
286 end | 291 end |
287 | 292 |
288 local function serve_hello(event) | 293 local function serve_hello(event) |
289 event.response.headers.content_type = "text/html;charset=utf-8" | 294 event.response.headers.content_type = "text/html;charset=utf-8" |