1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Skip empty parts when chunking

A zero-length chunk has a protocol-significant meaning: it signals the
end of the response. An empty part in a Rack body has no such meaning,
so we should just skip it.
This commit is contained in:
Matthew Draper 2015-07-18 09:01:33 +09:30
parent 7e2e56c2d4
commit 1ba0999685
2 changed files with 10 additions and 0 deletions

View file

@ -663,6 +663,7 @@ module Puma
begin
res_body.each do |part|
if chunked
next if part.bytesize.zero?
fast_write client, part.bytesize.to_s(16)
fast_write client, line_ending
fast_write client, part

View file

@ -101,6 +101,15 @@ class TestPersistent < Test::Unit::TestCase
assert_equal "HTTP/1.1 200 OK\r\nX-Header: Works\r\nTransfer-Encoding: chunked\r\n\r\n5\r\nHello\r\n7\r\nChunked\r\n0\r\n\r\n", lines(10)
end
def test_chunked_with_empty_part
@body << ""
@body << "Chunked"
@client << @valid_request
assert_equal "HTTP/1.1 200 OK\r\nX-Header: Works\r\nTransfer-Encoding: chunked\r\n\r\n5\r\nHello\r\n7\r\nChunked\r\n0\r\n\r\n", lines(10)
end
def test_no_chunked_in_http10
@body << "Chunked"