Class: Thin::Request

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

Constant Summary

WEBSOCKET_RECEIVE_CALLBACK =
'websocket.receive_callback'.freeze

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) secure_websocket?

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

- (Boolean) websocket?

Returns:

  • (Boolean)


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

def websocket?
  @env['HTTP_CONNECTION'] and
  @env['HTTP_CONNECTION'].split(/\s*,\s*/).include?('Upgrade') and
  ['WebSocket', 'websocket'].include?(@env['HTTP_UPGRADE'])
end

- (Object) websocket_upgrade_data



74
75
76
77
# File 'lib/thin_extensions.rb', line 74

def websocket_upgrade_data
  parser = Faye::WebSocket.parser(self)
  parser.handshake(self)
end

- (Object) websocket_url



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_URI'] }"
end