Software /
code /
prosody
Changeset
2483:2f235c57d713
net.httpserver: More robust handling of headers split across multiple packets
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 21 Jan 2010 14:53:01 +0000 |
parents | 2482:a1570e371258 |
children | 2484:cf924f587410 |
files | net/httpserver.lua |
diffstat | 1 files changed, 11 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/net/httpserver.lua Thu Jan 21 13:22:41 2010 +0000 +++ b/net/httpserver.lua Thu Jan 21 14:53:01 2010 +0000 @@ -142,22 +142,29 @@ elseif request.state == "headers" then log("debug", "Reading headers...") local pos = startpos; - local headers = request.headers or {}; + local headers, headers_complete = request.headers; + if not headers then + headers = {}; + request.headers = headers; + end + for line in data:gmatch("(.-)\r\n") do startpos = (startpos or 1) + #line + 2; local k, v = line:match("(%S+): (.+)"); if k and v then headers[k:lower()] = v; --- log("debug", "Header: "..k:lower().." = "..v); + --log("debug", "Header: '"..k:lower().."' = '"..v.."'"); elseif #line == 0 then - request.headers = headers; + headers_complete = true; break; else log("debug", "Unhandled header line: "..line); end end - if not expectbody(request) then + if not headers_complete then return; end + + if not expectbody(request) then call_callback(request); return; end