Class: Async::WebSocket::UpgradeRequest
- Inherits:
-
Protocol::HTTP::Request
- Object
- Protocol::HTTP::Request
- Async::WebSocket::UpgradeRequest
- Includes:
- Protocol::WebSocket::Headers
- Defined in:
- lib/async/websocket/upgrade_request.rb
Overview
This is required for HTTP/1.x to upgrade the connection to the WebSocket protocol.
Defined Under Namespace
Classes: Wrapper
Instance Method Summary collapse
- #call(connection) ⇒ Object
-
#initialize(request, protocols: [], version: 13, &block) ⇒ UpgradeRequest
constructor
A new instance of UpgradeRequest.
Constructor Details
#initialize(request, protocols: [], version: 13, &block) ⇒ UpgradeRequest
Returns a new instance of UpgradeRequest.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/async/websocket/upgrade_request.rb', line 51 def initialize(request, protocols: [], version: 13, &block) @key = Nounce.generate_key headers = ::Protocol::HTTP::Headers[request.headers] headers.add(SEC_WEBSOCKET_KEY, @key) headers.add(SEC_WEBSOCKET_VERSION, String(version)) if protocols.any? headers.add(SEC_WEBSOCKET_PROTOCOL, protocols.join(',')) end super(request.scheme, request., ::Protocol::HTTP::Methods::GET, request.path, nil, headers, nil, PROTOCOL) end |
Instance Method Details
#call(connection) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/async/websocket/upgrade_request.rb', line 66 def call(connection) response = super if accept_digest = response.headers[SEC_WEBSOCKET_ACCEPT]&.first expected_accept_digest = Nounce.accept_digest(@key) unless accept_digest and accept_digest == expected_accept_digest raise ProtocolError, "Invalid accept digest, expected #{expected_accept_digest.inspect}, got #{accept_digest.inspect}!" end end return Wrapper.new(response) end |