Class: Thin::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/thin_extensions.rb

Defined Under Namespace

Classes: Protocol75, Protocol76, WebSocketHandler

Constant Summary collapse

WEBSOCKET_RECEIVE_CALLBACK =
'websocket.receive_callback'.freeze

Instance Method Summary collapse

Instance Method Details

#websocket?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/thin_extensions.rb', line 57

def websocket?
  @env['HTTP_CONNECTION'] == 'Upgrade' && @env['HTTP_UPGRADE'] == 'WebSocket'
end

#websocket_upgrade_dataObject



66
67
68
69
70
71
72
73
# File 'lib/thin_extensions.rb', line 66

def websocket_upgrade_data
  handler = if @env['HTTP_SEC_WEBSOCKET_KEY1'] and @env['HTTP_SEC_WEBSOCKET_KEY2']
    Protocol76
  else
    Protocol75
  end
  handler.new(self).handshake
end

#websocket_urlObject



61
62
63
64
# File 'lib/thin_extensions.rb', line 61

def websocket_url
  scheme = (@env['HTTP_ORIGIN'] =~ /^https:/i) ? 'wss:' : 'ws:'
  @env['websocket.url'] = "#{ scheme }//#{ @env['HTTP_HOST'] }#{ @env['REQUEST_PATH'] }"
end