diff options
author | Waqas Hussain <waqas20@gmail.com> | 2009-12-27 10:09:22 +0500 |
---|---|---|
committer | Waqas Hussain <waqas20@gmail.com> | 2009-12-27 10:09:22 +0500 |
commit | c700f8867c7f78c5c4b27775aee0b638b24d5dda (patch) | |
tree | 45bdd9bc674f21c6ea2bb2c1b6f2e8cd35a32102 | |
parent | ea8ac406e621e35f1205e40757c140b5b5e4f4df (diff) | |
download | prosody-c700f8867c7f78c5c4b27775aee0b638b24d5dda.tar.gz prosody-c700f8867c7f78c5c4b27775aee0b638b24d5dda.zip |
net.httpserver: Optimized response serialization.
-rw-r--r-- | net/httpserver.lua | 27 |
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 |