drbrain / net-http-persistent

Thread-safe persistent connections with Net::HTTP
http://seattlerb.rubyforge.org/net-http-persistent
339 stars 117 forks source link

2nd request unable to redefine read_timeout after 1st request #33

Closed mislav closed 12 years ago

mislav commented 12 years ago

I'm making 2 requests to the same local server, each instantiating a new Persistent object.

require 'net/http/persistent'
require 'uri'

def req uri, timeout = false
  uri = URI(uri.to_s)
  http = Net::HTTP::Persistent.new 'Faraday'
  request = Net::HTTPGenericRequest.new 'GET', false, true, uri.request_uri
  http.read_timeout = timeout if timeout != false
  http.request uri, request
end

# 1st GET request with no timeout
req('http://127.0.0.1:4567/echo', nil)

begin
  # "/slow" is a resource that sleeps for 10 seconds
  p req('http://127.0.0.1:4567/slow', 1)
  abort "this shouldn't happen!"
rescue Net::HTTP::Persistent::Error
  puts $!.message
  puts "Good."
end
drbrain commented 12 years ago

Currently read_timeout is only set when the connection is started. I'll rearrange some things to make it settable per-request.

drbrain commented 12 years ago

Oops, that should say "request"