diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-06-13 23:42:54 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-06-13 23:42:54 +0000 |
commit | c297fde2000dcc8bdf7cb9f912fb2ea07be1c282 (patch) | |
tree | bc85e7c18aa4620b38ad0083e3ebc0eb32ff481d /test/unit | |
parent | 131c241840990753f7b75344092058ef7434ea8b (diff) | |
download | unicorn-c297fde2000dcc8bdf7cb9f912fb2ea07be1c282.tar.gz |
This allows one to enter the dechunker without parsing HTTP headers beforehand. Since we skipped header parsing, trailer parsing is not supported since we don't know what trailers might be (to our knowledge, nobody uses trailers anyways)
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/test_http_parser_ng.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/test/unit/test_http_parser_ng.rb b/test/unit/test_http_parser_ng.rb index e57428c..2b2fe41 100644 --- a/test/unit/test_http_parser_ng.rb +++ b/test/unit/test_http_parser_ng.rb @@ -237,6 +237,17 @@ class HttpParserNgTest < Test::Unit::TestCase assert @parser.keepalive? end + def test_chunked_empty + str = @parser.buf + req = @parser.env + str << "PUT / HTTP/1.1\r\ntransfer-Encoding: chunked\r\n\r\n" + assert_equal req, @parser.parse, "msg=#{str}" + assert_equal 0, str.size + tmp = "" + assert_equal str, @parser.filter_body(tmp, str << "0\r\n\r\n") + assert_equal "", tmp + end + def test_two_chunks str = @parser.buf str << "PUT / HTTP/1.1\r\ntransfer-Encoding: chunked\r\n\r\n" @@ -651,4 +662,47 @@ class HttpParserNgTest < Test::Unit::TestCase assert_equal expect, @parser.parse assert ! @parser.next? end + + def test_chunk_only + tmp = "" + assert_equal @parser, @parser.dechunk! + assert_nil @parser.filter_body(tmp, "6\r\n") + assert_equal "", tmp + assert_nil @parser.filter_body(tmp, "abcdef") + assert_equal "abcdef", tmp + assert_nil @parser.filter_body(tmp, "\r\n") + assert_equal "", tmp + src = "0\r\n\r\n" + assert_equal src.object_id, @parser.filter_body(tmp, src).object_id + assert_equal "", tmp + end + + def test_chunk_only_bad_align + tmp = "" + assert_equal @parser, @parser.dechunk! + assert_nil @parser.filter_body(tmp, "6\r\na") + assert_equal "a", tmp + assert_nil @parser.filter_body(tmp, "bcde") + assert_equal "bcde", tmp + assert_nil @parser.filter_body(tmp, "f\r") + assert_equal "f", tmp + src = "\n0\r\n\r\n" + assert_equal src.object_id, @parser.filter_body(tmp, src).object_id + assert_equal "", tmp + end + + def test_chunk_only_reset_ok + tmp = "" + assert_equal @parser, @parser.dechunk! + src = "1\r\na\r\n0\r\n\r\n" + assert_nil @parser.filter_body(tmp, src) + assert_equal "a", tmp + assert_equal src.object_id, @parser.filter_body(tmp, src).object_id + + assert_equal @parser, @parser.dechunk! + src = "0\r\n\r\n" + assert_equal src.object_id, @parser.filter_body(tmp, src).object_id + assert_equal "", tmp + assert_equal src, @parser.filter_body(tmp, src) + end end |