From: jdshewey@... Date: 2018-02-05T19:07:20+00:00 Subject: [ruby-core:85414] [Ruby trunk Bug#14451] HTTP responses with Content-Length: 0 cause a failure Issue #14451 has been reported by jdshewey (James Shewey). ---------------------------------------- Bug #14451: HTTP responses with Content-Length: 0 cause a failure https://bugs.ruby-lang.org/issues/14451 * 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: