Skip to content
Browse files

Merge branch 'error-on-empty-header'

  • Loading branch information...
2 parents 87cd9e9 + ffdca36 commit b9d439cd3494db3225587ccf7cb060f4b37a9f13 @mloughran committed Apr 19, 2012
Showing with 9 additions and 0 deletions.
  1. +2 −0 lib/em-websocket/handler_factory.rb
  2. +7 −0 spec/unit/handler_spec.rb
View
2 lib/em-websocket/handler_factory.rb
@@ -15,6 +15,8 @@ def self.build(connection, data, secure = false, debug = false)
lines = header.split("\r\n")
+ raise HandshakeError, "Empty HTTP header" unless lines.size > 0
+
# extract request path
first_line = lines.shift.match(PATH)
raise HandshakeError, "Invalid HTTP header" unless first_line
View
7 spec/unit/handler_spec.rb
@@ -138,6 +138,13 @@ def handler(request, secure = false)
}.should raise_error(EM::WebSocket::HandshakeError, 'Invalid Key "12998 5 Y3 1.P00"')
end
+ it "should raise error if the HTTP header is empty" do
+ connection = Object.new
+ lambda {
+ EM::WebSocket::HandlerFactory.build(connection, "\r\n\r\nfoobar", false)
+ }.should raise_error(EM::WebSocket::HandshakeError, "Empty HTTP header")
+ end
+
it "should leave request with incomplete header" do
data = format_request(@request)
# Sends only half of the request

0 comments on commit b9d439c

Please sign in to comment.
Something went wrong with that request. Please try again.