about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-04-21 11:14:39 -0700
committerEric Wong <normalperson@yhbt.net>2009-04-21 11:16:21 -0700
commited4f50016ab0eab1ebbeac2fe1d0fd8712c7ee91 (patch)
tree5c232a2f34271090ad6512d565ee2f3aee39e7af /test
parent357fb0a21fdfe6ff3af522a2463248e20b2fa8be (diff)
downloadunicorn-ed4f50016ab0eab1ebbeac2fe1d0fd8712c7ee91.tar.gz
It's part of the HTTP/1.1 (rfc2616), so we might as well
handle it in there and set PATH_INFO while we're at it.

Also, make "OPTIONS *" test not fail Rack::Lint
Diffstat (limited to 'test')
-rw-r--r--test/unit/test_http_parser.rb14
-rw-r--r--test/unit/test_request.rb43
2 files changed, 52 insertions, 5 deletions
diff --git a/test/unit/test_http_parser.rb b/test/unit/test_http_parser.rb
index f6fdd47..37a539d 100644
--- a/test/unit/test_http_parser.rb
+++ b/test/unit/test_http_parser.rb
@@ -103,6 +103,20 @@ class HttpParserTest < Test::Unit::TestCase
     assert_nil req['QUERY_STRING']
   end
 
+  def test_absolute_uri
+    parser = HttpParser.new
+    req = {}
+    http = "GET http://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 'example.com', req['HTTP_HOST'] # TODO
+    # assert_equal 'example.com', req['SERVER_NAME'] # TODO
+  end
+
   def test_put_body_oneshot
     parser = HttpParser.new
     req = {}
diff --git a/test/unit/test_request.rb b/test/unit/test_request.rb
index 0613326..dbe4069 100644
--- a/test/unit/test_request.rb
+++ b/test/unit/test_request.rb
@@ -38,23 +38,56 @@ class RequestTest < Test::Unit::TestCase
                              "Host: foo\r\n\r\n")
     res = env = nil
     assert_nothing_raised { env = @request.read(client) }
-    assert_equal '*', env['REQUEST_PATH']
-    assert_equal '*', env['PATH_INFO']
+    assert_equal '', env['REQUEST_PATH']
+    assert_equal '', env['PATH_INFO']
     assert_equal '*', env['REQUEST_URI']
-
-    # assert_nothing_raised { res = @lint.call(env) } # fails Rack lint
+    assert_nothing_raised { res = @lint.call(env) }
   end
 
-  def test_full_url_path
+  def test_absolute_uri_with_query
     client = MockRequest.new("GET http://e:3/x?y=z HTTP/1.1\r\n" \
                              "Host: foo\r\n\r\n")
     res = env = nil
     assert_nothing_raised { env = @request.read(client) }
     assert_equal '/x', env['REQUEST_PATH']
     assert_equal '/x', env['PATH_INFO']
+    assert_equal 'y=z', env['QUERY_STRING']
     assert_nothing_raised { res = @lint.call(env) }
   end
 
+  def test_absolute_uri_with_fragment
+    client = MockRequest.new("GET http://e:3/x#frag HTTP/1.1\r\n" \
+                             "Host: foo\r\n\r\n")
+    res = env = nil
+    assert_nothing_raised { env = @request.read(client) }
+    assert_equal '/x', env['REQUEST_PATH']
+    assert_equal '/x', env['PATH_INFO']
+    assert_equal '', env['QUERY_STRING']
+    assert_equal 'frag', env['FRAGMENT']
+    assert_nothing_raised { res = @lint.call(env) }
+  end
+
+  def test_absolute_uri_with_query_and_fragment
+    client = MockRequest.new("GET http://e:3/x?a=b#frag HTTP/1.1\r\n" \
+                             "Host: foo\r\n\r\n")
+    res = env = nil
+    assert_nothing_raised { env = @request.read(client) }
+    assert_equal '/x', env['REQUEST_PATH']
+    assert_equal '/x', env['PATH_INFO']
+    assert_equal 'a=b', env['QUERY_STRING']
+    assert_equal 'frag', env['FRAGMENT']
+    assert_nothing_raised { res = @lint.call(env) }
+  end
+
+  def test_absolute_uri_unsupported_schemes
+    %w(ssh+http://e/ ftp://e/x http+ssh://e/x).each do |abs_uri|
+      client = MockRequest.new("GET #{abs_uri} HTTP/1.1\r\n" \
+                               "Host: foo\r\n\r\n")
+      assert_raises(HttpParserError) { @request.read(client) }
+      @request.reset
+    end
+  end
+
   def test_x_forwarded_proto_https
     res = env = nil
     client = MockRequest.new("GET / HTTP/1.1\r\n" \