From ba916e542a46686185cb701e87a98a617c0f4078 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 21 Apr 2009 11:14:49 -0700 Subject: http11: make parser obey HTTP_HOST with empty port This means "Host: foo-bar:" (trailing colon) will assume server_port is 80, not a blank string. --- test/unit/test_http_parser.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test') diff --git a/test/unit/test_http_parser.rb b/test/unit/test_http_parser.rb index 1f3c9d2..50dfea7 100644 --- a/test/unit/test_http_parser.rb +++ b/test/unit/test_http_parser.rb @@ -43,6 +43,39 @@ class HttpParserTest < Test::Unit::TestCase assert_equal '', req['QUERY_STRING'] end + def test_parse_server_host_default_port + parser = HttpParser.new + req = {} + assert parser.execute(req, "GET / HTTP/1.1\r\nHost: foo\r\n\r\n") + assert_equal 'foo', req['SERVER_NAME'] + assert_equal '80', req['SERVER_PORT'] + end + + def test_parse_server_host_alt_port + parser = HttpParser.new + req = {} + assert parser.execute(req, "GET / HTTP/1.1\r\nHost: foo:999\r\n\r\n") + assert_equal 'foo', req['SERVER_NAME'] + assert_equal '999', req['SERVER_PORT'] + end + + def test_parse_server_host_empty_port + parser = HttpParser.new + req = {} + assert parser.execute(req, "GET / HTTP/1.1\r\nHost: foo:\r\n\r\n") + assert_equal 'foo', req['SERVER_NAME'] + assert_equal '80', req['SERVER_PORT'] + end + + def test_parse_server_host_xfp_https + parser = HttpParser.new + req = {} + assert parser.execute(req, "GET / HTTP/1.1\r\nHost: foo:\r\n" \ + "X-Forwarded-Proto: https\r\n\r\n") + assert_equal 'foo', req['SERVER_NAME'] + assert_equal '443', req['SERVER_PORT'] + end + def test_parse_strange_headers parser = HttpParser.new req = {} -- cgit v1.2.3-24-ge0c7