Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/net/http/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ def read_chunked(dest, chunk_data_io) # :nodoc:
total = 0
while true
line = self.class.read_line(@socket, MAX_RESPONSE_HEADER_LENGTH).chop
hexlen = line.slice(/[0-9a-fA-F]+/) or
hexlen = line[/\A\h+(?=[ \t]*(?:;|\r?\z))/] or
raise Net::HTTPBadResponse, "wrong chunk size line: #{line}"
len = hexlen.hex
break if len == 0
Expand Down
19 changes: 19 additions & 0 deletions test/net/http/test_httpresponse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,25 @@ def test_read_body
assert_equal 'hello', body
end

def test_chunk_size_line
["1f", "1F", "1f;ext=1", "1f ;ext", "1f\t; ext=\"a\""].each do |size|
io = dummy_io("HTTP/1.1 200 OK\nConnection: close\nTransfer-Encoding: chunked\n\n" \
"#{size}\n#{"a" * 31}\n0\n\n")
res = Net::HTTPResponse.read_new(io)
res.reading_body(io, true) {}
assert_equal("a" * 31, res.body, size)
end

["0x1f", "1_0", ";ext=1f", "zz1f", "-5", "+5", "g5", " 5", "5x"].each do |size|
io = dummy_io("HTTP/1.1 200 OK\nConnection: close\nTransfer-Encoding: chunked\n\n" \
"#{size}\n#{"a" * 31}\n0\n\n")
res = Net::HTTPResponse.read_new(io)
assert_raise(Net::HTTPBadResponse, size) do
res.reading_body(io, true) {}
end
end
end

def test_read_body_chunked_is_final_transfer_coding
io = dummy_io(<<EOS)
HTTP/1.1 200 OK
Expand Down
Loading