Permalink
Browse files

report error if server closes keepalive (fix #225)

  • Loading branch information...
1 parent ee337a5 commit 96150413eeae5a52783e6eceee672044edd31373 @igrigorik igrigorik committed Jun 22, 2013
Showing with 28 additions and 7 deletions.
  1. +1 −1 lib/em-http/client.rb
  2. +4 −2 lib/em-http/http_connection.rb
  3. +23 −4 spec/client_spec.rb
View
@@ -115,7 +115,7 @@ def unbind(reason = nil)
end
else
- on_error(reason)
+ on_error(reason || 'connection closed by server')
end
end
@@ -52,7 +52,9 @@ def conn=(c)
def activate_connection(client)
begin
- EventMachine.bind_connect(@connopts.bind, @connopts.bind_port, @connopts.host, @connopts.port, HttpStubConnection) do |conn|
+ EventMachine.bind_connect(@connopts.bind, @connopts.bind_port,
+ @connopts.host, @connopts.port,
+ HttpStubConnection) do |conn|
post_init
@deferred = false
@@ -167,7 +169,7 @@ def redirect(client)
@pending.push client
end
- def unbind(reason)
+ def unbind(reason = nil)
@clients.map { |c| c.unbind(reason) }
if r = @pending.shift
View
@@ -761,22 +761,41 @@ def failed(http=nil)
it "should reconnect if connection was closed between requests" do
EventMachine.run {
- conn = EM::HttpRequest.new('http://127.0.0.1:8090/', :inactivity_timeout => 0.5)
- req = conn.get :keepalive => true
+ conn = EM::HttpRequest.new('http://127.0.0.1:8090/')
+ req = conn.get
req.callback do
- EM.add_timer(1) do
- req = conn.get
+ conn.close('client closing connection')
+ EM.next_tick do
+ req = conn.get :path => "/gzip"
req.callback do
req.response_header.status.should == 200
+ req.response.should match('compressed')
EventMachine.stop
end
end
end
}
end
+ it "should report error if connection was closed by server on client keepalive requests" do
+ EventMachine.run {
+ conn = EM::HttpRequest.new('http://127.0.0.1:8090/')
+ req = conn.get :keepalive => true
+
+ req.callback do
+ req = conn.get
+
+ req.callback { failed(http) }
+ req.errback do
+ req.error.should match('connection closed by server')
+ EventMachine.stop
+ end
+ end
+ }
+ end
+
it 'should handle malformed Content-Type header repetitions' do
EventMachine.run {
response =<<-HTTP.gsub(/^ +/, '').strip

0 comments on commit 9615041

Please sign in to comment.