Error when using body stream with chunked
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
#1 Updated by Yui NARUSE almost 2 years ago
- Tracker changed from Bug to Backport
- Project changed from Ruby trunk to Backport193
- Status changed from Open to Assigned
- Assignee set to Usaku NAKAMURA
- Priority changed from 5 to Normal
- Target version deleted (
r35281 fixes it but it is too large.
So 1.9.3 should fix this as shekhei says.
#2 Updated by Usaku NAKAMURA almost 2 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 [Backport #8176].