aboutsummaryrefslogtreecommitdiffstats
path: root/net/http/server.lua
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2013-01-22 08:30:38 +0500
committerWaqas Hussain <waqas20@gmail.com>2013-01-22 08:30:38 +0500
commit8c8ebcc4aeb65184408557a5d3f967dd2b0e7e51 (patch)
tree9938dd9411cf02b2c7cc7a82103633f7378030b8 /net/http/server.lua
parentf9b9d6c4d2b71e142bc7cd254bc91171e32b2825 (diff)
parent4808daf39fd7b3d3de0e2c25e871dcbacbed1299 (diff)
downloadprosody-8c8ebcc4aeb65184408557a5d3f967dd2b0e7e51.tar.gz
prosody-8c8ebcc4aeb65184408557a5d3f967dd2b0e7e51.zip
Merge 0.9->trunk
Diffstat (limited to 'net/http/server.lua')
-rw-r--r--net/http/server.lua17
1 files changed, 14 insertions, 3 deletions
diff --git a/net/http/server.lua b/net/http/server.lua
index 69908e4e..7cf25009 100644
--- a/net/http/server.lua
+++ b/net/http/server.lua
@@ -156,12 +156,23 @@ function handle_request(conn, request, finish_cb)
local date_header = os_date('!%a, %d %b %Y %H:%M:%S GMT'); -- FIXME use
local conn_header = request.headers.connection;
- local keep_alive = conn_header == "Keep-Alive" or (request.httpversion == "1.1" and conn_header ~= "close");
+ conn_header = conn_header and ","..conn_header:gsub("[ \t]", ""):lower().."," or ""
+ local httpversion = request.httpversion
+ local persistent = conn_header:find(",keep-alive,", 1, true)
+ or (httpversion == "1.1" and not conn_header:find(",close,", 1, true));
+
+ local response_conn_header;
+ if persistent then
+ response_conn_header = "Keep-Alive";
+ else
+ response_conn_header = httpversion == "1.1" and "close" or nil
+ end
local response = {
request = request;
status_code = 200;
- headers = { date = date_header, connection = (keep_alive and "Keep-Alive" or "close") };
+ headers = { date = date_header, connection = response_conn_header };
+ persistent = persistent;
conn = conn;
send = _M.send_response;
finish_cb = finish_cb;
@@ -241,7 +252,7 @@ function _M.send_response(response, body)
response:on_destroy();
response.on_destroy = nil;
end
- if headers.connection == "Keep-Alive" then
+ if response.persistent then
response:finish_cb();
else
response.conn:close();