Actions
Backport #8176
closedError when using body stream with chunked
Status:
Closed
Assignee:
Description
When using body stream and chunk in 1.9.3-p392, when it calls
def send_request_with_body_stream(sock, ver, path, f)
unless content_length() or chunked?
raise ArgumentError,
"Content-Length not given and Transfer-Encoding is not `chunked'"
end
supply_default_content_type
write_header sock, ver, path
wait_for_continue sock, ver if sock.continue_timeout
if chunked?
while s = f.read(1024)
sock.write(sprintf("%x\r\n", s.length) << s << "\r\n")
end
sock.write "0\r\n\r\n"
else
while s = f.read(1024)
sock.write s
end
end
end
it often causes the receiving server to close the connection as the length is apparently wrong.
In Ruby2, the code has been changed to using bytesize instead of length, after quite a bit of debugging,
while s = f.read(1024)
puts sprintf("%x\r\n", s.length)
puts sprintf("%x\r\n", s.bytesize)
sock.write(sprintf("%x\r\n", s.length) << s << "\r\n")
end
quite a number of times, the two values are not matching. And when i change the code to use s.bytesize instead of s.length, the problem never appears again
Actions
Like0
Like0Like0