about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-12-14 06:59:51 +0000
committerEric Wong <e@80x24.org>2016-12-14 08:02:52 +0000
commitd34fed5788c4ca8175ca4ef210041ae0348f56f4 (patch)
tree90149d22c0e302433c86ee8e6a800d130e7fe54c /test
parent7fe9d585056ea5002cd789d70c3ea4bd5000759c (diff)
downloadyahns-d34fed5788c4ca8175ca4ef210041ae0348f56f4.tar.gz
Setting "Transfer-Encoding: chunked" on responses will confuse
clients which see a 204 response and do not expect a body.
This follows Rack::Chunked behavior, as yahns should function
without Rack::Chunked middleware.

This regression appeared in yahns v1.13.0 (2016-08-05)
Diffstat (limited to 'test')
-rw-r--r--test/test_auto_chunk.rb22
1 files changed, 21 insertions, 1 deletions
diff --git a/test/test_auto_chunk.rb b/test/test_auto_chunk.rb
index a97fe26..e1847f6 100644
--- a/test/test_auto_chunk.rb
+++ b/test/test_auto_chunk.rb
@@ -18,7 +18,12 @@ class TestAutoChunk < Testcase
         app = Rack::Builder.new do
           use Rack::ContentType, "text/plain"
           run(lambda do |env|
-            [ 200, {}, %w(a b c) ]
+            case env['PATH_INFO']
+            when '/204'
+              [ 204, {}, [] ]
+            else
+              [ 200, {}, %w(a b c) ]
+            end
           end)
         end
         app(:rack, app) { listen "#{host}:#{port}" }
@@ -50,6 +55,21 @@ class TestAutoChunk < Testcase
       assert_equal 200, res.code.to_i
       assert_equal 'abc', res.body
     end
+
+    s = TCPSocket.new(host, port)
+    s.write("GET /204 HTTP/1.1\r\nHost: example.com\r\n\r\n")
+    buf = s.readpartial(1024)
+    assert_match %r{\r\n\r\n\z}, buf
+    refute_match %r{^Transfer-Encoding}i, buf
+    assert_match %r{^Connection: keep-alive\r\n}, buf
+    assert_nil IO.select([s], nil, nil, 1), 'connection persists..'
+
+    # maek sure another on the same connection works
+    s.write("GET / HTTP/1.1\r\nHost: example.com\r\n\r\n")
+    buf = s.readpartial(1024)
+    assert_match %r{\AHTTP/1\.1 200}, buf
+    assert_match(%r{^Transfer-Encoding: chunked\r\n}, buf)
+    s.close
   ensure
     quit_wait(pid)
   end