From 954ab725367d274e814a6cf1fe9b3bad836315b0 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 5 Aug 2009 03:07:45 +0100 Subject: net.httpserver: Allow response.body to be a non-string --- net/httpserver.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/net/httpserver.lua b/net/httpserver.lua index 699e0324..57c8eede 100644 --- a/net/httpserver.lua +++ b/net/httpserver.lua @@ -37,6 +37,7 @@ local function send_response(request, response) -- Write status line local resp; if response.body then + local body = 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; @@ -48,15 +49,15 @@ local function send_response(request, response) t_insert(resp, "\r\n"); end end - if response.body and not (h and h["Content-Length"]) then + if not (h and h["Content-Length"]) then t_insert(resp, "Content-Length: "); - t_insert(resp, #response.body); + t_insert(resp, #body); t_insert(resp, "\r\n"); end t_insert(resp, "\r\n"); - if response.body and request.method ~= "HEAD" then - t_insert(resp, response.body); + if request.method ~= "HEAD" then + t_insert(resp, body); end else -- Response we have is just a string (the body) -- cgit v1.2.3 From fef360b4dd88c409b5cacbed161bdd6cfd043396 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 5 Aug 2009 03:08:21 +0100 Subject: mod_bosh: Fix error reply for host-unknown errors --- plugins/mod_bosh.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mod_bosh.lua b/plugins/mod_bosh.lua index 744893c4..743ebdef 100644 --- a/plugins/mod_bosh.lua +++ b/plugins/mod_bosh.lua @@ -136,8 +136,8 @@ function stream_callbacks.streamopened(request, attr) if not hosts[attr.to] then -- Unknown host log("debug", "BOSH client tried to connect to unknown host: %s", tostring(attr.to)); - session_close_reply.attr.condition = "host-unknown"; - request:send{ headers = default_headers, body = tostring(session_close_reply) }; + session_close_reply.body.attr.condition = "host-unknown"; + request:send(session_close_reply); request.notopen = nil return; end -- cgit v1.2.3