Software /
code /
prosody
Comparison
net/http/server.lua @ 5300:fcb1be0b4a5c
net.http.server: Properly handle persistent connections
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Sat, 12 Jan 2013 17:26:50 +0100 |
parent | 4788:e14f5a156571 |
child | 5333:760c345dc7a1 |
comparison
equal
deleted
inserted
replaced
5299:cc9d460aa779 | 5300:fcb1be0b4a5c |
---|---|
154 request.headers = headers; | 154 request.headers = headers; |
155 request.conn = conn; | 155 request.conn = conn; |
156 | 156 |
157 local date_header = os_date('!%a, %d %b %Y %H:%M:%S GMT'); -- FIXME use | 157 local date_header = os_date('!%a, %d %b %Y %H:%M:%S GMT'); -- FIXME use |
158 local conn_header = request.headers.connection; | 158 local conn_header = request.headers.connection; |
159 local keep_alive = conn_header == "Keep-Alive" or (request.httpversion == "1.1" and conn_header ~= "close"); | 159 conn_header = conn_header and ","..conn_header:gsub("[ \t]", ""):lower().."," or "" |
160 local httpversion = request.httpversion | |
161 local persistent = conn_header:find(",keep-alive,", 1, true) | |
162 or (httpversion == "1.1" and not conn_header:find(",close,", 1, true)); | |
163 | |
164 local response_conn_header; | |
165 if persistent then | |
166 response_conn_header = "Keep-Alive"; | |
167 else | |
168 response_conn_header = httpversion == "1.1" and "close" or nil | |
169 end | |
160 | 170 |
161 local response = { | 171 local response = { |
162 request = request; | 172 request = request; |
163 status_code = 200; | 173 status_code = 200; |
164 headers = { date = date_header, connection = (keep_alive and "Keep-Alive" or "close") }; | 174 headers = { date = date_header, connection = response_conn_header }; |
175 persistent = persistent; | |
165 conn = conn; | 176 conn = conn; |
166 send = _M.send_response; | 177 send = _M.send_response; |
167 finish_cb = finish_cb; | 178 finish_cb = finish_cb; |
168 }; | 179 }; |
169 conn._http_open_response = response; | 180 conn._http_open_response = response; |
239 response.conn:write(t_concat(output)); | 250 response.conn:write(t_concat(output)); |
240 if response.on_destroy then | 251 if response.on_destroy then |
241 response:on_destroy(); | 252 response:on_destroy(); |
242 response.on_destroy = nil; | 253 response.on_destroy = nil; |
243 end | 254 end |
244 if headers.connection == "Keep-Alive" then | 255 if response.persistent then |
245 response:finish_cb(); | 256 response:finish_cb(); |
246 else | 257 else |
247 response.conn:close(); | 258 response.conn:close(); |
248 end | 259 end |
249 end | 260 end |