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/2 to establish a connection using 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.



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/async/websocket/connect_request.rb', line 70

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



84
85
86
87
88
# File 'lib/async/websocket/connect_request.rb', line 84

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