mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Add test and fix for corner case when reading chunked request body.
This seems to happen only when the first chunk is larger than 4096 bytes (the amount read from the socket at once) and when a pause happens between the CR and LF characters that follow the size part of the next chunk.
This commit is contained in:
parent
b9a499d4c8
commit
684fe08355
2 changed files with 33 additions and 0 deletions
|
@ -147,6 +147,7 @@ module Puma
|
||||||
if @partial_part_left <= chunk.size
|
if @partial_part_left <= chunk.size
|
||||||
@body << chunk[0..(@partial_part_left-3)] # skip the \r\n
|
@body << chunk[0..(@partial_part_left-3)] # skip the \r\n
|
||||||
chunk = chunk[@partial_part_left..-1]
|
chunk = chunk[@partial_part_left..-1]
|
||||||
|
@partial_part_left = 0
|
||||||
else
|
else
|
||||||
@body << chunk
|
@body << chunk
|
||||||
@partial_part_left -= chunk.size
|
@partial_part_left -= chunk.size
|
||||||
|
|
|
@ -658,6 +658,38 @@ EOF
|
||||||
assert_equal "hello", body
|
assert_equal "hello", body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_chunked_request_pause_between_cr_lf_after_size_of_second_chunk
|
||||||
|
body = nil
|
||||||
|
@server.app = proc { |env|
|
||||||
|
body = env['rack.input'].read
|
||||||
|
[200, {}, [""]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@server.add_tcp_listener @host, @port
|
||||||
|
@server.run
|
||||||
|
|
||||||
|
part1 = 'a' * 4200
|
||||||
|
|
||||||
|
chunked_body = "#{part1.size.to_s(16)}\r\n#{part1}\r\n1\r\nb\r\n0\r\n\r\n"
|
||||||
|
|
||||||
|
sock = TCPSocket.new @host, @server.connected_port
|
||||||
|
sock << "PUT /path HTTP/1.1\r\nConnection: close\r\nTransfer-Encoding: chunked\r\n\r\n"
|
||||||
|
|
||||||
|
sleep 0.1
|
||||||
|
|
||||||
|
sock << chunked_body[0..-10]
|
||||||
|
|
||||||
|
sleep 0.1
|
||||||
|
|
||||||
|
sock << chunked_body[-9..-1]
|
||||||
|
|
||||||
|
data = sock.read
|
||||||
|
|
||||||
|
assert_equal "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Length: 0\r\n\r\n", data
|
||||||
|
assert_equal (part1 + 'b'), body
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def test_chunked_request_header_case
|
def test_chunked_request_header_case
|
||||||
body = nil
|
body = nil
|
||||||
@server.app = proc { |env|
|
@server.app = proc { |env|
|
||||||
|
|
Loading…
Reference in a new issue