Software /
code /
prosody
Comparison
net/httpserver.lua @ 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 |
parent | 2481:9b407a6acf39 |
child | 2570:9e69aecad25e |
comparison
equal
deleted
inserted
replaced
2482:a1570e371258 | 2483:2f235c57d713 |
---|---|
140 end | 140 end |
141 end | 141 end |
142 elseif request.state == "headers" then | 142 elseif request.state == "headers" then |
143 log("debug", "Reading headers...") | 143 log("debug", "Reading headers...") |
144 local pos = startpos; | 144 local pos = startpos; |
145 local headers = request.headers or {}; | 145 local headers, headers_complete = request.headers; |
146 if not headers then | |
147 headers = {}; | |
148 request.headers = headers; | |
149 end | |
150 | |
146 for line in data:gmatch("(.-)\r\n") do | 151 for line in data:gmatch("(.-)\r\n") do |
147 startpos = (startpos or 1) + #line + 2; | 152 startpos = (startpos or 1) + #line + 2; |
148 local k, v = line:match("(%S+): (.+)"); | 153 local k, v = line:match("(%S+): (.+)"); |
149 if k and v then | 154 if k and v then |
150 headers[k:lower()] = v; | 155 headers[k:lower()] = v; |
151 -- log("debug", "Header: "..k:lower().." = "..v); | 156 --log("debug", "Header: '"..k:lower().."' = '"..v.."'"); |
152 elseif #line == 0 then | 157 elseif #line == 0 then |
153 request.headers = headers; | 158 headers_complete = true; |
154 break; | 159 break; |
155 else | 160 else |
156 log("debug", "Unhandled header line: "..line); | 161 log("debug", "Unhandled header line: "..line); |
157 end | 162 end |
158 end | 163 end |
159 | 164 |
160 if not expectbody(request) then | 165 if not headers_complete then return; end |
166 | |
167 if not expectbody(request) then | |
161 call_callback(request); | 168 call_callback(request); |
162 return; | 169 return; |
163 end | 170 end |
164 | 171 |
165 -- Reached the end of the headers | 172 -- Reached the end of the headers |