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

#secure_websocket?Boolean

Returns:

  • (Boolean)


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

def secure_websocket?
  if @env.has_key?('HTTP_X_FORWARDED_PROTO')
    @env['HTTP_X_FORWARDED_PROTO'] == 'https' 
  else
    @env['HTTP_ORIGIN'] =~ /^https:/i
  end
end

#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



74
75
76
77
78
79
80
81
# File 'lib/thin_extensions.rb', line 74

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



69
70
71
72
# File 'lib/thin_extensions.rb', line 69

def websocket_url
  scheme = secure_websocket? ? 'wss:' : 'ws:'
  @env['websocket.url'] = "#{ scheme }//#{ @env['HTTP_HOST'] }#{ @env['REQUEST_PATH'] }"
end