Permalink
Browse files

Check if headers exist instead of crashing

This should solve problems with Rack::Test, which does not pass the Connection header.
  • Loading branch information...
1 parent 31f0a66 commit 47799b1a3315574172624c0f6506b79804c283e1 @ttencate committed Jun 5, 2012
Showing with 2 additions and 1 deletion.
  1. +2 −1 lib/sinatra-websocket/ext/sinatra/request.rb
@@ -5,7 +5,8 @@ module Request
# Taken from skinny https://github.com/sj26/skinny and updated to support Firefox
def websocket?
- env['HTTP_CONNECTION'].split(',').map(&:strip).map(&:downcase).include?('upgrade') &&
+ env['HTTP_CONNECTION'] && env['HTTP_UPGRADE'] &&
+ env['HTTP_CONNECTION'].split(',').map(&:strip).map(&:downcase).include?('upgrade') &&
env['HTTP_UPGRADE'].downcase == 'websocket'
end

0 comments on commit 47799b1

Please sign in to comment.