Skip to content

Commit

Permalink
handle bad HTTP responses, fail the request
Browse files Browse the repository at this point in the history
  • Loading branch information
igrigorik committed Mar 10, 2011
1 parent 83edb72 commit 6d36a5b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/em-http/http_connection.rb
Expand Up @@ -77,7 +77,12 @@ def use(klass)
end

def receive_data(data)
@p << data
begin
@p << data
rescue HTTP::Parser::Error => e
c = @clients.shift
c.on_error(e.message)
end
end

def connection_completed
Expand Down
2 changes: 1 addition & 1 deletion lib/em-http/version.rb
@@ -1,5 +1,5 @@
module EventMachine
class HttpRequest
VERSION = "1.0.0.beta.1"
VERSION = "1.0.0.beta.2"
end
end
13 changes: 13 additions & 0 deletions spec/client_spec.rb
Expand Up @@ -558,6 +558,19 @@ def failed(http=nil)
}
}
end

it "should handle invalid HTTP response" do
EventMachine.run {
@s = StubServer.new("<html></html>")

http = EventMachine::HttpRequest.new('http://127.0.0.1:8081/').get
http.callback { failed(http) }
http.errback {
http.error.should_not be_nil
EM.stop
}
}
end
end

it "should stream a file off disk" do
Expand Down

0 comments on commit 6d36a5b

Please sign in to comment.