Module: SinatraWebsocket::Ext::Sinatra::Request

Defined in:
lib/sinatra-websocket/ext/sinatra/request.rb

Instance Method Summary collapse

Instance Method Details

#websocket(options = {}, &blk) ⇒ Object

Taken from skinny github.com/sj26/skinny


14
15
16
17
18
19
# File 'lib/sinatra-websocket/ext/sinatra/request.rb', line 14

def websocket(options={}, &blk)
  env['skinny.websocket'] ||= begin
    raise Error::ConnectionError.new("Not a WebSocket request") unless websocket?
    SinatraWebsocket::Connection.from_env(env, options, &blk)
  end
end

#websocket?Boolean

Taken from skinny github.com/sj26/skinny and updated to support Firefox


7
8
9
10
11
# File 'lib/sinatra-websocket/ext/sinatra/request.rb', line 7

def websocket?
  env['HTTP_CONNECTION'] && env['HTTP_UPGRADE'] &&
    env['HTTP_CONNECTION'].split(',').map(&:strip).map(&:downcase).include?('upgrade') &&
    env['HTTP_UPGRADE'].downcase == 'websocket'
end