Class: Async::WebSocket::Request

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scheme = nil, authority = nil, path = nil, headers = nil, **options, &block) ⇒ Request

Returns a new instance of Request.



33
34
35
36
37
38
39
40
41
42
# File 'lib/async/websocket/request.rb', line 33

def initialize(scheme = nil, authority = nil, path = nil, headers = nil, **options, &block)
	@scheme = scheme
	@authority = authority
	@path = path
	@headers = headers
	
	@options = options
	
	@body = nil
end

Instance Attribute Details

#authorityObject

Returns the value of attribute authority.



45
46
47
# File 'lib/async/websocket/request.rb', line 45

def authority
  @authority
end

#bodyObject

Returns the value of attribute body.



49
50
51
# File 'lib/async/websocket/request.rb', line 49

def body
  @body
end

#headersObject

Returns the value of attribute headers.



47
48
49
# File 'lib/async/websocket/request.rb', line 47

def headers
  @headers
end

#pathObject

Returns the value of attribute path.



46
47
48
# File 'lib/async/websocket/request.rb', line 46

def path
  @path
end

#schemeObject

Returns the value of attribute scheme.



44
45
46
# File 'lib/async/websocket/request.rb', line 44

def scheme
  @scheme
end

Class Method Details

.websocket?(request) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/async/websocket/request.rb', line 29

def self.websocket?(request)
	Array(request.protocol).include?(PROTOCOL)
end

Instance Method Details

#call(connection) ⇒ Object

Send the request to the given connection.

Raises:

  • (HTTP::Error)


52
53
54
55
56
57
58
59
60
# File 'lib/async/websocket/request.rb', line 52

def call(connection)
	if connection.http1?
		return UpgradeRequest.new(self, **@options).call(connection)
	elsif connection.http2?
		return ConnectRequest.new(self, **@options).call(connection)
	end
	
	raise HTTP::Error, "Unsupported HTTP version: #{connection.version}!"
end

#idempotent?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/async/websocket/request.rb', line 62

def idempotent?
	true
end

#to_sObject



66
67
68
# File 'lib/async/websocket/request.rb', line 66

def to_s
	"\#<#{self.class} #{@scheme}://#{@authority}: #{@path}>"
end