Class: Async::WebSocket::ConnectRequest

Inherits:
Protocol::HTTP::Request
  • Object
show all
Includes:
Protocol::WebSocket::Headers
Defined in:
lib/async/websocket/connect_request.rb

Overview

This is required for HTTP/1.x to upgrade the connection to the WebSocket protocol. See tools.ietf.org/html/rfc8441 for more details.

Defined Under Namespace

Classes: Hijack, Wrapper

Instance Method Summary collapse

Constructor Details

#initialize(request, protocols: [], version: 13, &block) ⇒ ConnectRequest

Returns a new instance of ConnectRequest.



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/async/websocket/connect_request.rb', line 82

def initialize(request, protocols: [], version: 13, &block)
	body = Hijack.new(self)
	
	headers = ::Protocol::HTTP::Headers[request.headers]
	
	headers.add(SEC_WEBSOCKET_VERSION, String(version))
	
	if protocols.any?
		headers.add(SEC_WEBSOCKET_PROTOCOL, protocols.join(','))
	end
	
	super(request.scheme, request.authority, ::Protocol::HTTP::Methods::CONNECT, request.path, nil, headers, body, PROTOCOL)
end

Instance Method Details

#call(connection) ⇒ Object



96
97
98
99
100
# File 'lib/async/websocket/connect_request.rb', line 96

def call(connection)
	response = super
	
	Wrapper.new(@body.stream, response)
end