aboutsummaryrefslogtreecommitdiffstats
path: root/net/httpserver.lua
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2009-12-27 10:09:22 +0500
committerWaqas Hussain <waqas20@gmail.com>2009-12-27 10:09:22 +0500
commitc700f8867c7f78c5c4b27775aee0b638b24d5dda (patch)
tree45bdd9bc674f21c6ea2bb2c1b6f2e8cd35a32102 /net/httpserver.lua
parentea8ac406e621e35f1205e40757c140b5b5e4f4df (diff)
downloadprosody-c700f8867c7f78c5c4b27775aee0b638b24d5dda.tar.gz
prosody-c700f8867c7f78c5c4b27775aee0b638b24d5dda.zip
net.httpserver: Optimized response serialization.
Diffstat (limited to 'net/httpserver.lua')
-rw-r--r--net/httpserver.lua27
1 files changed, 11 insertions, 16 deletions
diff --git a/net/httpserver.lua b/net/httpserver.lua
index 6273bbb9..dec13a0b 100644
--- a/net/httpserver.lua
+++ b/net/httpserver.lua
@@ -39,40 +39,35 @@ local function send_response(request, response)
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"};
+ resp = { "HTTP/1.0 "..(response.status or "200 OK").."\r\n" };
local h = response.headers;
if h then
for k, v in pairs(h) do
- t_insert(resp, k);
- t_insert(resp, ": ");
- t_insert(resp, v);
- t_insert(resp, "\r\n");
+ t_insert(resp, k..": "..v.."\r\n");
end
end
if not (h and h["Content-Length"]) then
- t_insert(resp, "Content-Length: ");
- t_insert(resp, #body);
- t_insert(resp, "\r\n");
+ t_insert(resp, "Content-Length: "..#body.."\r\n");
end
t_insert(resp, "\r\n");
if request.method ~= "HEAD" then
t_insert(resp, body);
end
+ request.write(t_concat(resp));
else
-- Response we have is just a string (the body)
log("debug", "Sending 200 response to %s", request.id or "<none>");
- resp = { "HTTP/1.0 200 OK\r\n" };
- t_insert(resp, "Connection: close\r\n");
- t_insert(resp, "Content-Type: text/html\r\n");
- t_insert(resp, "Content-Length: ");
- t_insert(resp, #response);
- t_insert(resp, "\r\n\r\n");
+ local resp = "HTTP/1.0 200 OK\r\n"
+ .. "Connection: close\r\n"
+ .. "Content-Type: text/html\r\n"
+ .. "Content-Length: "..#response.."\r\n"
+ .. "\r\n"
+ .. response;
- t_insert(resp, response);
+ request.write(resp);
end
- request.write(t_concat(resp));
if not request.stayopen then
request:destroy();
end