Permalink
Browse files

apply timeout settings on redirects, closes #198

  • Loading branch information...
1 parent a39d98e commit e39f4a75e1db3cccc0edaf0dea57acb6e9f72991 @igrigorik committed Jul 4, 2012
Showing with 21 additions and 0 deletions.
  1. +2 −0 lib/em-http/http_connection.rb
  2. +15 −0 spec/redirect_spec.rb
  3. +4 −0 spec/stallion.rb
@@ -182,6 +182,8 @@ def unbind(reason)
@conn.reconnect(r.req.host, r.req.port)
end
+ @conn.pending_connect_timeout = @connopts.connect_timeout
+ @conn.comm_inactivity_timeout = @connopts.inactivity_timeout
@conn.callback { r.connection_completed }
rescue EventMachine::ConnectionError => e
@clients.pop.close(e.message)
View
@@ -185,6 +185,21 @@ def response(r)
}
end
+ it "should apply timeout settings on redirects" do
+ EventMachine.run {
+ t = Time.now.to_i
+ EventMachine.heartbeat_interval = 0.1
+
+ conn = EventMachine::HttpRequest.new('http://127.0.0.1:8090/redirect/timeout', :inactivity_timeout => 0.1)
+ http = conn.get :redirects => 1
+ http.callback { failed(http) }
+ http.errback {
+ (Time.now.to_i - t).should <= 1
+ EM.stop
+ }
+ }
+ end
+
it "should capture and pass cookies on redirect and pass_cookies by default" do
EventMachine.run {
http = EventMachine::HttpRequest.new('http://127.0.0.1:8090/redirect/multiple-with-cookie').get :redirects => 2, :head => {'cookie' => 'id=2;'}
View
@@ -150,6 +150,10 @@ def self.call(env)
stable.response.status = 301
stable.response["Location"] = "http://127.0.0.1:8090"
+ elsif stable.request.path_info == '/redirect/timeout'
+ stable.response.status = 301
+ stable.response["Location"] = "http://127.0.0.1:8090/timeout"
+
elsif stable.request.path_info == '/redirect/head'
stable.response.status = 301
stable.response["Location"] = "/"

0 comments on commit e39f4a7

Please sign in to comment.