net/httpserver.lua

changeset 2837
a17e73ab5f4c
parent 2836
dfb5fa77d437
child 2877
1edeb8fe7d14
equal deleted inserted replaced
2836:dfb5fa77d437 2837:a17e73ab5f4c
144 end 144 end
145 end 145 end
146 elseif request.state == "headers" then 146 elseif request.state == "headers" then
147 log("debug", "Reading headers...") 147 log("debug", "Reading headers...")
148 local pos = startpos; 148 local pos = startpos;
149 local headers = request.headers or {}; 149 local headers, headers_complete = request.headers;
150 if not headers then
151 headers = {};
152 request.headers = headers;
153 end
154
150 for line in data:gmatch("(.-)\r\n") do 155 for line in data:gmatch("(.-)\r\n") do
151 startpos = (startpos or 1) + #line + 2; 156 startpos = (startpos or 1) + #line + 2;
152 local k, v = line:match("(%S+): (.+)"); 157 local k, v = line:match("(%S+): (.+)");
153 if k and v then 158 if k and v then
154 headers[k:lower()] = v; 159 headers[k:lower()] = v;
155 -- log("debug", "Header: "..k:lower().." = "..v); 160 --log("debug", "Header: '"..k:lower().."' = '"..v.."'");
156 elseif #line == 0 then 161 elseif #line == 0 then
157 request.headers = headers; 162 headers_complete = true;
158 break; 163 break;
159 else 164 else
160 log("debug", "Unhandled header line: "..line); 165 log("debug", "Unhandled header line: "..line);
161 end 166 end
162 end 167 end
163 168
164 if not expectbody(request) then 169 if not headers_complete then return; end
170
171 if not expectbody(request) then
165 call_callback(request); 172 call_callback(request);
166 return; 173 return;
167 end 174 end
168 175
169 -- Reached the end of the headers 176 -- Reached the end of the headers

mercurial