133 |
|
delete [] port; |
134 |
|
} |
135 |
|
|
136 |
+ |
// putline("Referer: " + ?referer?); |
137 |
|
putline("Connection: close"); |
138 |
|
putline(); |
139 |
|
|
152 |
|
unsigned dot = line.find('.'); |
153 |
|
unsigned space = line.find(' '); |
154 |
|
|
155 |
< |
unsigned major = strtoul(line.substr(5, dot - 5).c_str(), 0, 0); |
156 |
< |
unsigned minor = strtoul(line.substr(dot + 1, space - dot - 1).c_str(), 0, |
157 |
< |
0); |
155 |
> |
unsigned major = strtoul(line.substr(5, dot - 5).c_str(), 0, 10); |
156 |
> |
unsigned minor = strtoul(line.substr(dot + 1, space - dot - 1).c_str(), |
157 |
> |
0, 10); |
158 |
|
|
159 |
|
if (major > 1 || minor < 1) |
160 |
|
{ |
161 |
< |
cerr << program << ": Potentially Incompatible Server: HTTP/" << major |
162 |
< |
<< "." << minor << "\n"; |
161 |
> |
cerr << program << ": Potentially Incompatible Server: HTTP/" << |
162 |
> |
major << "." << minor << "\n"; |
163 |
|
|
164 |
|
return answer; |
165 |
|
} |
166 |
|
|
167 |
< |
response = code(strtoul(line.substr(space + 1).c_str(), 0, 0)); |
167 |
> |
response = code(strtoul(line.substr(space + 1).c_str(), 0, 10)); |
168 |
|
|
169 |
|
if (response < ok) do line = getline(); while (line != ""); |
170 |
|
} |
183 |
|
|
184 |
|
while (isspace(value[0])) value.erase(0, 1); |
185 |
|
|
186 |
< |
// if (field = |
186 |
> |
if (field == "Content-Type") |
187 |
> |
{ |
188 |
> |
type = value; |
189 |
> |
} |
190 |
> |
else if (field == "Content-Length") |
191 |
> |
{ |
192 |
> |
length = strtoul(value.c_str(), 0, 10); |
193 |
> |
} |
194 |
> |
else if (field == "Location") |
195 |
> |
{ |
196 |
> |
location = value; |
197 |
> |
} |
198 |
> |
else if (field == "Transfer-Encoding") |
199 |
> |
{ |
200 |
> |
chunked = value == "chunked"; |
201 |
> |
} |
202 |
|
} |
203 |
|
} |
204 |
|
while (line != ""); |
233 |
|
break; |
234 |
|
} |
235 |
|
|
236 |
+ |
if (!head && answer) populate(); |
237 |
+ |
|
238 |
|
return answer; |
239 |
|
} |
240 |
|
|
290 |
|
chunked = false; |
291 |
|
} |
292 |
|
|
293 |
+ |
void HttpHandler::populate() |
294 |
+ |
{ |
295 |
+ |
if (!chunked) |
296 |
+ |
{ |
297 |
+ |
unsigned left = length; |
298 |
+ |
|
299 |
+ |
while (left > 0) |
300 |
+ |
{ |
301 |
+ |
memset(buffer, 0, BUFSIZ + 1); |
302 |
+ |
|
303 |
+ |
unsigned bytes = left > BUFSIZ ? BUFSIZ : left; |
304 |
+ |
|
305 |
+ |
if (recv(http, buffer, bytes, 0) == SOCKET_ERROR) |
306 |
+ |
{ |
307 |
+ |
error(program + ": Revc"); |
308 |
+ |
exit(1); |
309 |
+ |
} |
310 |
+ |
|
311 |
+ |
page += buffer; |
312 |
+ |
left -= bytes; |
313 |
+ |
} |
314 |
+ |
} |
315 |
+ |
else |
316 |
+ |
{ |
317 |
+ |
// |
318 |
+ |
} |
319 |
+ |
|
320 |
+ |
cerr << "\n[" << page << "]\n"; |
321 |
+ |
} |
322 |
+ |
|
323 |
|
void HttpHandler::putline(const string line) |
324 |
|
{ |
325 |
|
sprintf(buffer, "%s\r\n", line.c_str()); |