diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-04-21 11:14:51 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-04-21 11:16:35 -0700 |
commit | b031b9d2cb1bd0434ce2891ce20a65a5b5b29796 (patch) | |
tree | 1c7f97ba44ae08e751bff4ba59f0c8f308ebe22d /test/unit/test_http_parser.rb | |
parent | b57718fb7ed6f813f41b655ecbab1f6edd64ded0 (diff) | |
download | unicorn-b031b9d2cb1bd0434ce2891ce20a65a5b5b29796.tar.gz |
We now parse the scheme, host and port from Absolute URIs and ignore them if the equivalents are specified in the other headers.
Diffstat (limited to 'test/unit/test_http_parser.rb')
-rw-r--r-- | test/unit/test_http_parser.rb | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/test/unit/test_http_parser.rb b/test/unit/test_http_parser.rb index 50dfea7..ce1213f 100644 --- a/test/unit/test_http_parser.rb +++ b/test/unit/test_http_parser.rb @@ -146,8 +146,43 @@ class HttpParserTest < Test::Unit::TestCase 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 + assert_equal 'example.com', req['HTTP_HOST'] + assert_equal 'example.com', req['SERVER_NAME'] + assert_equal '80', req['SERVER_PORT'] + end + + # X-Forwarded-Proto is not in rfc2616, absolute URIs are, however... + def test_absolute_uri_https + parser = HttpParser.new + req = {} + http = "GET https://example.com/foo?q=bar HTTP/1.1\r\n" \ + "X-Forwarded-Proto: http\r\n\r\n" + assert parser.execute(req, http) + assert_equal 'https', 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'] + assert_equal 'example.com', req['SERVER_NAME'] + assert_equal '443', req['SERVER_PORT'] + end + + # Host: header should be ignored for absolute URIs + def test_absolute_uri_with_port + parser = HttpParser.new + req = {} + http = "GET http://example.com:8080/foo?q=bar HTTP/1.2\r\n" \ + "Host: bad.example.com\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:8080', req['HTTP_HOST'] + assert_equal 'example.com', req['SERVER_NAME'] + assert_equal '8080', req['SERVER_PORT'] end def test_put_body_oneshot |