Project

General

Profile

Actions

Bug #14451

closed

HTTP responses with Content-Length: 0 cause a failure

Added by jdshewey (James Shewey) over 6 years ago. Updated over 5 years ago.

Status:
Third Party's Issue
Assignee:
-
Target version:
-
ruby -v:
ruby 2.0.0p648
[ruby-core:85414]

Description

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:

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.

Updated by lzap (Lukas Zapletal) over 5 years ago

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

Actions #2

Updated by duerst (Martin Dürst) over 5 years ago

  • Status changed from Open to Third Party's Issue
Actions

Also available in: Atom PDF

Like0
Like0Like0