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: Wrapper

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ConnectRequest.



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

def initialize(request, protocols: [], version: 13)
	body = Async::HTTP::Body::Writable.new
	
	headers = []
	
	headers << [SEC_WEBSOCKET_VERSION, version]
	
	if protocols.any?
		headers << [SEC_WEBSOCKET_PROTOCOL, protocols.join(',')]
	end
	
	merged_headers = ::Protocol::HTTP::Headers::Merged.new(request.headers, headers)
	
	super(request.scheme, request.authority, ::Protocol::HTTP::Methods::CONNECT, request.path, nil, merged_headers, body, PROTOCOL)
end

Instance Method Details

#call(connection) ⇒ Object



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

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