Bug #14451

HTTP responses with Content-Length: 0 cause a failure

Added by jdshewey (James Shewey) over 2 years ago. Updated about 1 year ago.

Third Party's Issue
Target version:
ruby -v:
ruby 2.0.0p648


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 ( 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 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:

require 'rest-client'

result = RestClient::Request.execute(method: :post, url: 'http:/', 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.

Updated by lzap (Lukas Zapletal) about 1 year ago

Hello, thanks for report. REST Client is actually not part of Ruby, feel free to move the report there:


Updated by duerst (Martin Dürst) about 1 year ago

  • Status changed from Open to Third Party's Issue

Also available in: Atom PDF