diff options
author | Waqas Hussain <waqas20@gmail.com> | 2013-01-22 08:30:38 +0500 |
---|---|---|
committer | Waqas Hussain <waqas20@gmail.com> | 2013-01-22 08:30:38 +0500 |
commit | 0f2d3d7139c741b6bd8714048694ee16a9b11c91 (patch) | |
tree | 9938dd9411cf02b2c7cc7a82103633f7378030b8 /net | |
parent | 1ae08f23d712da167747a7d59feac9965d6ef9ac (diff) | |
parent | b1f22daa932ac857022412e734533ff05bad1594 (diff) | |
download | prosody-0f2d3d7139c741b6bd8714048694ee16a9b11c91.tar.gz prosody-0f2d3d7139c741b6bd8714048694ee16a9b11c91.zip |
Merge 0.9->trunk
Diffstat (limited to 'net')
-rw-r--r-- | net/http/parser.lua | 1 | ||||
-rw-r--r-- | net/http/server.lua | 17 | ||||
-rw-r--r-- | net/server_event.lua | 14 | ||||
-rw-r--r-- | net/server_select.lua | 2 |
4 files changed, 25 insertions, 9 deletions
diff --git a/net/http/parser.lua b/net/http/parser.lua index b53dfa4e..64cf38c0 100644 --- a/net/http/parser.lua +++ b/net/http/parser.lua @@ -77,6 +77,7 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) end end end + if not first_line then error = true; return error_cb("invalid-status-line"); end len = tonumber(headers["content-length"]); -- TODO check for invalid len if client then -- FIXME handle '100 Continue' response (by skipping it) 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(); diff --git a/net/server_event.lua b/net/server_event.lua index e69530ff..08926939 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -40,6 +40,9 @@ local tostring = use "tostring" local coroutine = use "coroutine" local setmetatable = use "setmetatable" +local t_insert = table.insert +local t_concat = table.concat + local ssl = use "ssl" local socket = use "socket" or require "socket" @@ -309,7 +312,7 @@ do debug( "error:", err ) -- to much, check your app return nil, err end - self.writebuffer = self.writebuffer .. data -- new buffer + t_insert(self.writebuffer, data) -- new buffer self.writebufferlen = total if not self.eventwrite then -- register new write event --vdebug( "register new write event" ) @@ -466,7 +469,7 @@ do type = "client"; conn = client; currenttime = socket_gettime( ); -- safe the origin - writebuffer = ""; -- writebuffer + writebuffer = {}; -- writebuffer writebufferlen = 0; -- length of writebuffer send = client.send; -- caching table lookups receive = client.receive; @@ -520,10 +523,11 @@ do interface.eventwritetimeout = false end end - local succ, err, byte = interface.conn:send( interface.writebuffer, 1, interface.writebufferlen ) + interface.writebuffer = { t_concat(interface.writebuffer) } + local succ, err, byte = interface.conn:send( interface.writebuffer[1], 1, interface.writebufferlen ) --vdebug( "write data:", interface.writebuffer, "error:", err, "part:", byte ) if succ then -- writing succesful - interface.writebuffer = "" + interface.writebuffer[1] = nil interface.writebufferlen = 0 interface:ondrain(); if interface.fatalerror then @@ -539,7 +543,7 @@ do return -1 elseif byte and (err == "timeout" or err == "wantwrite") then -- want write again --vdebug( "writebuffer is not empty:", err ) - interface.writebuffer = string_sub( interface.writebuffer, byte + 1, interface.writebufferlen ) -- new buffer + interface.writebuffer[1] = string_sub( interface.writebuffer[1], byte + 1, interface.writebufferlen ) -- new buffer interface.writebufferlen = interface.writebufferlen - byte if "wantread" == err then -- happens only with luasec local callback = function( ) diff --git a/net/server_select.lua b/net/server_select.lua index 97b9f199..0852d444 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -74,6 +74,7 @@ local idfalse local closeall local addsocket local addserver +local addtimer local getserver local wrapserver local getsettings @@ -237,7 +238,6 @@ wrapserver = function( listeners, socket, ip, serverport, pattern, sslctx, maxco local client, err = accept( socket ) -- try to accept if client then local ip, clientport = client:getpeername( ) - client:settimeout( 0 ) local handler, client, err = wrapconnection( handler, listeners, client, ip, serverport, clientport, pattern, sslctx ) -- wrap new client socket if err then -- error while wrapping ssl socket return false |