r17611 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17610‎ | r17611 | r17612 >
Date:12:12, 13 November 2006
Author:river
Status:old
Tags:
Comment:
instead of inserting headers we don't want and removing them later, let header_parser know about them and not insert them in the first place
Modified paths:
  • /trunk/willow/src/willow/whttp.cc (modified) (history)
  • /trunk/willow/src/willow/whttp_header.cc (modified) (history)

Diff [purge]

Index: trunk/willow/src/willow/whttp.cc
@@ -229,20 +229,6 @@
230230 delete _blist;
231231 }
232232
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 -
247233 void
248234 httpcllr::header_read_complete(void)
249235 {
@@ -256,8 +242,6 @@
257243 * Now parse the client's headers and decide what to do with
258244 * the request.
259245 */
260 - for (const char **s = removable_headers; *s; ++s)
261 - _header_parser._headers.remove(*s);
262246 _header_parser._headers.add("Connection", "close");
263247 _header_parser._headers.add("X-Forwarded-For", _client_socket->straddr().c_str());
264248
@@ -374,8 +358,6 @@
375359 void
376360 httpcllr::backend_read_headers_done(void)
377361 {
378 - for (const char **s = removable_headers; *s; ++s)
379 - _backend_headers._headers.remove(*s);
380362 _backend_headers._headers.add("Connection", "close");
381363
382364 _response = _backend_headers._response;
@@ -524,7 +506,7 @@
525507 wsocket *socks[2];
526508 map<wsocket *, int>::iterator lsnit;
527509
528 - if (s->read((char *)socks, sizeof(socks)) < sizeof(socks)) {
 510+ if (s->read((char *)socks, sizeof(socks)) < (int)sizeof(socks)) {
529511 wlog(WLOG_ERROR, format("accept_wakeup: reading fd: %e"));
530512 exit(1);
531513 }
Index: trunk/willow/src/willow/whttp_header.cc
@@ -32,6 +32,27 @@
3333
3434 using namespace wnet;
3535
 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+
3657 const char *request_string[] = {
3758 "GET ",
3859 "POST ",
@@ -49,6 +70,18 @@
5071 { NULL, 0, REQTYPE_INVALID }
5172 };
5273
 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+
5386 static int
5487 find_reqtype(char const *str, int len)
5588 {
@@ -309,6 +342,9 @@
310343 return io::sink_result_error;
311344 }
312345 nlen = value - name;
 346+ if (is_removable(name, nlen))
 347+ goto next;
 348+
313349 value++;
314350 while (isspace(*value) && value < rn)
315351 value++;