about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-05-23 21:04:56 +0000
committerEric Wong <normalperson@yhbt.net>2011-05-23 21:04:56 +0000
commit1b31c40997ff8b932a457275e9a2f219de1d32c8 (patch)
treeba36c1c8feeb3a962b6039a98105df8b06e504c9 /test
parent947704e3f8e67b8262815838e87b331802c7ba67 (diff)
downloadunicorn-1b31c40997ff8b932a457275e9a2f219de1d32c8.tar.gz
RFC 2616, section 4.2:
> The field-content does not include any leading or trailing LWS:
> linear white space occurring before the first non-whitespace
> character of the field-value or after the last non-whitespace
> character of the field-value. Such leading or trailing LWS MAY be
> removed without changing the semantics of the field value. Any LWS
> that occurs between field-content MAY be replaced with a single SP
> before interpreting the field value or forwarding the message
> downstream.
Diffstat (limited to 'test')
-rw-r--r--test/unit/test_http_parser.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/unit/test_http_parser.rb b/test/unit/test_http_parser.rb
index dc1aab7..70bb789 100644
--- a/test/unit/test_http_parser.rb
+++ b/test/unit/test_http_parser.rb
@@ -258,6 +258,20 @@ class HttpParserTest < Test::Unit::TestCase
     assert_equal 'hi y x ASDF', req['HTTP_X_ASDF']
   end
 
+  def test_continuation_eats_trailing_spaces
+    parser = HttpParser.new
+    header = "GET / HTTP/1.1\r\n" \
+             "X-ASDF:      \r\n" \
+             "\t\r\n" \
+             "  b  \r\n" \
+             "  ASDF\r\n\r\n"
+    parser.buf << header
+    req = parser.env
+    assert_equal req, parser.parse
+    assert_equal '', parser.buf
+    assert_equal 'b ASDF', req['HTTP_X_ASDF']
+  end
+
   def test_continuation_with_absolute_uri_and_ignored_host_header
     parser = HttpParser.new
     header = "GET http://example.com/ HTTP/1.1\r\n" \
@@ -764,6 +778,48 @@ class HttpParserTest < Test::Unit::TestCase
 
   end
 
+  def test_leading_tab
+    parser = HttpParser.new
+    get = "GET / HTTP/1.1\r\nHost:\texample.com\r\n\r\n"
+    assert parser.add_parse(get)
+    assert_equal 'example.com', parser.env['HTTP_HOST']
+  end
+
+  def test_trailing_whitespace
+    parser = HttpParser.new
+    get = "GET / HTTP/1.1\r\nHost: example.com \r\n\r\n"
+    assert parser.add_parse(get)
+    assert_equal 'example.com', parser.env['HTTP_HOST']
+  end
+
+  def test_trailing_tab
+    parser = HttpParser.new
+    get = "GET / HTTP/1.1\r\nHost: example.com\t\r\n\r\n"
+    assert parser.add_parse(get)
+    assert_equal 'example.com', parser.env['HTTP_HOST']
+  end
+
+  def test_trailing_multiple_linear_whitespace
+    parser = HttpParser.new
+    get = "GET / HTTP/1.1\r\nHost: example.com\t \t \t\r\n\r\n"
+    assert parser.add_parse(get)
+    assert_equal 'example.com', parser.env['HTTP_HOST']
+  end
+
+  def test_embedded_linear_whitespace_ok
+    parser = HttpParser.new
+    get = "GET / HTTP/1.1\r\nX-Space: hello\t world\t \r\n\r\n"
+    assert parser.add_parse(get)
+    assert_equal "hello\t world", parser.env["HTTP_X_SPACE"]
+  end
+
+  def test_empty_header
+    parser = HttpParser.new
+    get = "GET / HTTP/1.1\r\nHost:  \r\n\r\n"
+    assert parser.add_parse(get)
+    assert_equal '', parser.env['HTTP_HOST']
+  end
+
   # so we don't  care about the portability of this test
   # if it doesn't leak on Linux, it won't leak anywhere else
   # unless your C compiler or platform is otherwise broken