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
Updated by naruse (Yui NARUSE) over 10 years ago
- Tracker changed from Bug to Backport
- Project changed from Ruby master to Backport193
- Status changed from Open to Assigned
- Assignee set to usa (Usaku NAKAMURA)
- Priority changed from 5 to Normal
- Target version deleted (
2.6)
r35281 fixes it but it is too large.
So 1.9.3 should fix this as shekhei says.
Updated by usa (Usaku NAKAMURA) over 10 years ago
- Status changed from Assigned to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r42461.
shek hei , thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
- lib/net/http.rb (Net::HTTP#send_request_with_body_stream): use
String#bytesize instead of String#length.
reported by shekhei (shek hei wong) at [ruby-core:53775]
[Backport #8176].
Actions
Like0
Like0Like0