Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.

Commit

Permalink
Merge 5684110 into d7e7ee2
Browse files Browse the repository at this point in the history
  • Loading branch information
slivu committed Jun 6, 2013
2 parents d7e7ee2 + 5684110 commit 9c5d0a1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/reel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ module Reel
# Error reading a request
class RequestError < StandardError; end

# Error occured performing IO on a socket
# Error occurred performing IO on a socket
class SocketError < RequestError; end

# Error occurred when trying to use the socket after it was upgraded
class SocketUpgradedError < NilClass
def self.method_missing(m, *)
raise(Reel::RequestError, 'Reel::Connection#socket can not be used anymore as it was upgraded. Use Reel::WebSocket instance instead.')
end
end

# Error occured during a WebSockets handshake
class HandshakeError < RequestError; end

Expand Down
2 changes: 1 addition & 1 deletion lib/reel/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def request
@keepalive = false if req[CONNECTION] == CLOSE || req.version == HTTP_VERSION_1_0
when WebSocket
@request_state = @response_state = :websocket
@socket = nil
@socket = SocketUpgradedError
else raise "unexpected request type: #{req.class}"
end

Expand Down
15 changes: 15 additions & 0 deletions spec/reel/websocket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@
end
end

it "raises a RequestError when connection used after it was upgraded" do
with_socket_pair do |client, connection|
client << handshake.to_data
remote_host = "localhost"

connection.remote_host.should == remote_host

websocket = connection.request
websocket.should be_a Reel::WebSocket

lambda { connection.remote_host }.should raise_error(Reel::RequestError)
websocket.remote_host.should == remote_host
end
end

def with_websocket_pair
with_socket_pair do |client, connection|
client << handshake.to_data
Expand Down

0 comments on commit 9c5d0a1

Please sign in to comment.