# HG changeset patch # User Matthew Wild # Date 1264079692 0 # Node ID 9b407a6acf39dadee3242e63e59385653747cf8c # Parent 3596d181cfc37222d87b5981fdd8e1cb783096bb net.httpserver: Make it possible to return responses with no body diff -r 3596d181cfc3 -r 9b407a6acf39 net/httpserver.lua --- a/net/httpserver.lua Thu Jan 21 13:10:13 2010 +0000 +++ b/net/httpserver.lua Thu Jan 21 13:14:52 2010 +0000 @@ -36,8 +36,8 @@ local function send_response(request, response) -- Write status line local resp; - if response.body then - local body = tostring(response.body); + if response.body or response.headers then + local body = response.body and tostring(response.body); log("debug", "Sending response to %s", request.id); resp = { "HTTP/1.0 "..(response.status or "200 OK").."\r\n" }; local h = response.headers; @@ -46,12 +46,12 @@ t_insert(resp, k..": "..v.."\r\n"); end end - if not (h and h["Content-Length"]) then + if body and not (h and h["Content-Length"]) then t_insert(resp, "Content-Length: "..#body.."\r\n"); end t_insert(resp, "\r\n"); - if request.method ~= "HEAD" then + if body and request.method ~= "HEAD" then t_insert(resp, body); end request.write(t_concat(resp));