summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-04-21 11:14:56 -0700
committerEric Wong <normalperson@yhbt.net>2009-04-21 11:16:41 -0700
commit3dc43b27e2ab2740acda0514bb0d9562810b3df1 (patch)
tree944a9c5f86d5d7c876209a342932d77830cac0e0
parent3871cb11cfb68b6fa02a646caf3765e309d38494 (diff)
They aren't common, but apparently there exist
URLs with them, so we'll support them.
-rw-r--r--ext/unicorn/http11/http11_parser.h7
-rw-r--r--ext/unicorn/http11/http11_parser_common.rl2
-rw-r--r--test/unit/test_http_parser.rb16
3 files changed, 22 insertions, 3 deletions
diff --git a/ext/unicorn/http11/http11_parser.h b/ext/unicorn/http11/http11_parser.h
index 67aae71..8d95c59 100644
--- a/ext/unicorn/http11/http11_parser.h
+++ b/ext/unicorn/http11/http11_parser.h
@@ -808,6 +808,8 @@ st40:
         if ( ++p == pe )
                 goto _test_eof40;
 case 40:
+        if ( (*p) == 95 )
+                goto tr63;
         if ( (*p) < 48 ) {
                 if ( 45 <= (*p) && (*p) <= 46 )
                         goto tr63;
@@ -828,10 +830,11 @@ st41:
         if ( ++p == pe )
                 goto _test_eof41;
 case 41:
-#line 832 "http11_parser.h"
+#line 834 "http11_parser.h"
         switch( (*p) ) {
                 case 47: goto tr65;
                 case 58: goto st42;
+                case 95: goto st41;
         }
         if ( (*p) < 65 ) {
                 if ( 45 <= (*p) && (*p) <= 57 )
@@ -859,7 +862,7 @@ st43:
         if ( ++p == pe )
                 goto _test_eof43;
 case 43:
-#line 863 "http11_parser.h"
+#line 866 "http11_parser.h"
         if ( (*p) == 58 )
                 goto tr59;
         goto st0;
diff --git a/ext/unicorn/http11/http11_parser_common.rl b/ext/unicorn/http11/http11_parser_common.rl
index 567ed6b..ae01a55 100644
--- a/ext/unicorn/http11/http11_parser_common.rl
+++ b/ext/unicorn/http11/http11_parser_common.rl
@@ -25,7 +25,7 @@
 
 # URI schemes and absolute paths
   scheme = ( "http"i ("s"i)? ) $downcase_char >mark %scheme;
-  hostname = (alnum | "-" | ".")+;
+  hostname = (alnum | "-" | "." | "_")+;
   host_with_port = (hostname (":" digit*)?) >mark %host;
 
   path = ( pchar+ ( "/" pchar* )* ) ;
diff --git a/test/unit/test_http_parser.rb b/test/unit/test_http_parser.rb
index ce1213f..45e051a 100644
--- a/test/unit/test_http_parser.rb
+++ b/test/unit/test_http_parser.rb
@@ -136,6 +136,22 @@ class HttpParserTest < Test::Unit::TestCase
     assert_equal '', req['QUERY_STRING']
   end
 
+  # not common, but underscores do appear in practice
+  def test_absolute_uri_underscores
+    parser = HttpParser.new
+    req = {}
+    http = "GET http://under_score.example.com/foo?q=bar HTTP/1.0\r\n\r\n"
+    assert parser.execute(req, http)
+    assert_equal 'http', req['rack.url_scheme']
+    assert_equal '/foo?q=bar', req['REQUEST_URI']
+    assert_equal '/foo', req['REQUEST_PATH']
+    assert_equal 'q=bar', req['QUERY_STRING']
+
+    assert_equal 'under_score.example.com', req['HTTP_HOST']
+    assert_equal 'under_score.example.com', req['SERVER_NAME']
+    assert_equal '80', req['SERVER_PORT']
+  end
+
   def test_absolute_uri
     parser = HttpParser.new
     req = {}