Index: trunk/willow/src/willow/whttp.cc |
— | — | @@ -229,20 +229,6 @@ |
230 | 230 | delete _blist; |
231 | 231 | } |
232 | 232 | |
233 | | -static const char *removable_headers[] = { |
234 | | - "Connection", |
235 | | - "Keep-Alive", |
236 | | - "Proxy-Authenticate", |
237 | | - "Proxy-Authorization", |
238 | | - "Proxy-Connection", |
239 | | - "TE", |
240 | | - "Trailers", |
241 | | - "Upgrade", |
242 | | - "If-Modified-Since", |
243 | | - "Last-Modified", |
244 | | - NULL, |
245 | | -}; |
246 | | - |
247 | 233 | void |
248 | 234 | httpcllr::header_read_complete(void) |
249 | 235 | { |
— | — | @@ -256,8 +242,6 @@ |
257 | 243 | * Now parse the client's headers and decide what to do with |
258 | 244 | * the request. |
259 | 245 | */ |
260 | | - for (const char **s = removable_headers; *s; ++s) |
261 | | - _header_parser._headers.remove(*s); |
262 | 246 | _header_parser._headers.add("Connection", "close"); |
263 | 247 | _header_parser._headers.add("X-Forwarded-For", _client_socket->straddr().c_str()); |
264 | 248 | |
— | — | @@ -374,8 +358,6 @@ |
375 | 359 | void |
376 | 360 | httpcllr::backend_read_headers_done(void) |
377 | 361 | { |
378 | | - for (const char **s = removable_headers; *s; ++s) |
379 | | - _backend_headers._headers.remove(*s); |
380 | 362 | _backend_headers._headers.add("Connection", "close"); |
381 | 363 | |
382 | 364 | _response = _backend_headers._response; |
— | — | @@ -524,7 +506,7 @@ |
525 | 507 | wsocket *socks[2]; |
526 | 508 | map<wsocket *, int>::iterator lsnit; |
527 | 509 | |
528 | | - if (s->read((char *)socks, sizeof(socks)) < sizeof(socks)) { |
| 510 | + if (s->read((char *)socks, sizeof(socks)) < (int)sizeof(socks)) { |
529 | 511 | wlog(WLOG_ERROR, format("accept_wakeup: reading fd: %e")); |
530 | 512 | exit(1); |
531 | 513 | } |
Index: trunk/willow/src/willow/whttp_header.cc |
— | — | @@ -32,6 +32,27 @@ |
33 | 33 | |
34 | 34 | using namespace wnet; |
35 | 35 | |
| 36 | +/* |
| 37 | + * A list of headers we should remove from the request and the response |
| 38 | + * because we don't like them, or we want to insert our own. |
| 39 | + */ |
| 40 | +static const struct rmhdr_t { |
| 41 | + char *name; |
| 42 | + size_t len; |
| 43 | +} removable_headers[] = { |
| 44 | + { "Connection", sizeof("Connection") - 1 }, |
| 45 | + { "If-Modified-Since", sizeof("If-Modified-Since") - 1 }, |
| 46 | + { "Last-Modified", sizeof("Last-Modified") - 1 }, |
| 47 | + { "Keep-Alive", sizeof("Keep-Alive") - 1 }, |
| 48 | + { "TE", sizeof("TE") - 1 }, |
| 49 | + { "Trailers", sizeof("Trailers") - 1 }, |
| 50 | + { "Upgrade", sizeof("Upgrade") - 1 }, |
| 51 | + { "Proxy-Authenticate", sizeof("Proxy-Authenticate") - 1 }, |
| 52 | + { "Proxy-Authorization", sizeof("Proxy-Authorization") - 1 }, |
| 53 | + { "Proxy-Connection", sizeof("Proxy-Connection") - 1 }, |
| 54 | + { NULL, 0 } |
| 55 | +}; |
| 56 | + |
36 | 57 | const char *request_string[] = { |
37 | 58 | "GET ", |
38 | 59 | "POST ", |
— | — | @@ -49,6 +70,18 @@ |
50 | 71 | { NULL, 0, REQTYPE_INVALID } |
51 | 72 | }; |
52 | 73 | |
| 74 | +/* |
| 75 | + * Check if we should remove this header. |
| 76 | + */ |
| 77 | +static bool |
| 78 | +is_removable(char const *header, size_t hlen) |
| 79 | +{ |
| 80 | + for (rmhdr_t const *s = removable_headers; s->name; ++s) |
| 81 | + if (hlen == s->len && !strncasecmp(header, s->name, hlen)) |
| 82 | + return true; |
| 83 | + return false; |
| 84 | +} |
| 85 | + |
53 | 86 | static int |
54 | 87 | find_reqtype(char const *str, int len) |
55 | 88 | { |
— | — | @@ -309,6 +342,9 @@ |
310 | 343 | return io::sink_result_error; |
311 | 344 | } |
312 | 345 | nlen = value - name; |
| 346 | + if (is_removable(name, nlen)) |
| 347 | + goto next; |
| 348 | + |
313 | 349 | value++; |
314 | 350 | while (isspace(*value) && value < rn) |
315 | 351 | value++; |