[ruby-core:93062] [Ruby trunk Bug#14451] HTTP responses with Content-Length: 0 cause a failure
From:
lukas-x@...
Date:
2019-06-12 08:47:03 UTC
List:
ruby-core #93062
Issue #14451 has been updated by lzap (Lukas Zapletal).
Hello, thanks for report. REST Client is actually not part of Ruby, feel free to move the report there: https://github.com/rest-client/rest-client
----------------------------------------
Bug #14451: HTTP responses with Content-Length: 0 cause a failure
https://bugs.ruby-lang.org/issues/14451#change-78467
* Author: jdshewey (James Shewey)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.0.0p648
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
When a web server responds with a 200 OK without a body, if read_timeout is not set to nil, a Net::Timeout exception is thrown after 60 seconds. This is because ruby is stuck looping in rbuf_fill (https://github.com/ruby/ruby/blob/814daf855e0aa2c3a1164dc765378d3a092a1825/lib/net/protocol.rb) trying to read a response that will never come (or more precisely has already come in the header; there is no body to be read).
According to the RFC for JSON, for example (RFC7231 https://tools.ietf.org/html/rfc7231#section-6.3.1) a 0 content-length is a perfectly valid JSON response:
~~~
Aside from responses to CONNECT, a 200 response always has a payload,
though an origin server MAY generate a payload body of zero length.
~~~
I encountered this issue via the rest-client library and it appears that read_timeout is passed upstream to Net::HTTP. It can be reproduced with the following script:
~~~ ruby
require 'rest-client'
result = RestClient::Request.execute(method: :post, url: 'http:/mywebserver.com/', payload: {testkey: 'testvalue'}, headers: {accept: :json}, timeout: nil)
puts result.body
~~~
You would then need to configure the webserver to return a response with no body and a content-length of zero. I would suggest that Net:HTTP should check the response header for a content-length of zero and skip attempts to read the body in this event.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>