Skip to content

Commit

Permalink
Handle invalid WS connections with 400 response
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkdoor committed Oct 5, 2017
1 parent f2e3149 commit c9221f0
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/firehose/rack/consumer/web_socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ class Consumer
class WebSocket
# Setup a handler for the websocket connection.
def call(env)
ws = Faye::WebSocket.new(env)
if Consumer.multiplexing_request?(env)
MultiplexingHandler.new(ws)
else
DefaultHandler.new(ws)
begin
ws = Faye::WebSocket.new(env)
if Consumer.multiplexing_request?(env)
MultiplexingHandler.new(ws)
else
DefaultHandler.new(ws)
end
ws.rack_response
rescue StandardError => e
Firehose.logger.error "WS connection error: #{e.inspect}"
Firehose::Rack::Helpers.response(400, "Invalid WebSocket request")
end
ws.rack_response
end

# Determine if the rack request is a WebSocket request.
Expand Down

0 comments on commit c9221f0

Please sign in to comment.