about summary refs log tree commit homepage
path: root/ext
diff options
context:
space:
mode:
authorAugusto Becciu <augusto@jadedpixel.com>2010-06-07 23:02:43 -0300
committerEric Wong <normalperson@yhbt.net>2010-06-08 02:20:06 +0000
commit7d2295fa774d1c98dfbde2b09d93d58712253d24 (patch)
tree10acb007be88b3b07c3433cbd5280a16e18ea56a /ext
parented9cc7ba22bab5b3f7262d869a8bc03f14b2d4cb (diff)
downloadunicorn-7d2295fa774d1c98dfbde2b09d93d58712253d24.tar.gz
When Unicorn receives a request with a "Version" header, the
HttpParser transforms it into "HTTP_VERSION". After that tries to add
it to the request hash which already contains a "HTTP_VERSION" key
with the actual http version of the request. So it tries to append the
new value separated by a comma. But since the http version is a
freezed constant, the TypeError exception is raised.

According to the HTTP RFC
(http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7.1) a
"Version" header is valid. However, it's not supported in rack, since
rack has a HTTP_VERSION env variable for the http version. So I think
the easiest way to deal with this problem is to just ignore the header
since it is extremely unusual. We were getting it from a crappy bot.

ref: http://mid.gmane.org/AANLkTimuGgcwNAMcVZdViFWdF-UcW_RGyZAue7phUXps@mail.gmail.com

Acked-by: Eric Wong <normalperson@yhbt.net>
Diffstat (limited to 'ext')
-rw-r--r--ext/unicorn_http/unicorn_http.rl9
1 files changed, 9 insertions, 0 deletions
diff --git a/ext/unicorn_http/unicorn_http.rl b/ext/unicorn_http/unicorn_http.rl
index 264db68..aa23024 100644
--- a/ext/unicorn_http/unicorn_http.rl
+++ b/ext/unicorn_http/unicorn_http.rl
@@ -197,6 +197,15 @@ static void write_value(VALUE req, struct http_parser *hp,
     assert_frozen(f);
   }
 
+  /*
+   * ignore "Version" headers since they conflict with the HTTP_VERSION
+   * rack env variable.
+   */
+  if (rb_str_cmp(f, g_http_version) == 0) {
+    hp->cont = Qnil;
+    return;
+  }
+
   e = rb_hash_aref(req, f);
   if (NIL_P(e)) {
     hp->cont = rb_hash_aset(req, f, v);