Module: Ruflet::Rails::Protocol::WebSocketDetection

Included in:
Endpoint, WebApp
Defined in:
lib/ruflet/rails/protocol/websocket_detection.rb

Instance Method Summary collapse

Instance Method Details

#websocket_upgrade?(env) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
# File 'lib/ruflet/rails/protocol/websocket_detection.rb', line 7

def websocket_upgrade?(env)
  return false unless env["REQUEST_METHOD"] == "GET"

  upgrade    = env["HTTP_UPGRADE"].to_s.downcase
  connection = env["HTTP_CONNECTION"].to_s.downcase
  key        = env["HTTP_SEC_WEBSOCKET_KEY"].to_s

  upgrade == "websocket" && connection.include?("upgrade") && !key.empty?
end