Class: WebSocketRb::Wrapper::HandshakeRequest
- Inherits:
-
Object
- Object
- WebSocketRb::Wrapper::HandshakeRequest
- Defined in:
- lib/web_socket_rb/wrapper/handshake_request.rb
Constant Summary collapse
- HTTP_HEADER =
GET /chat HTTP/1.1
/^GET (\/[[:graph:]]*[\/[[:graph:]]]*) HTTP\/([[:digit:]]+\.[[:digit:]]+)$/- VERSION =
13- PROTOCOL =
'json'.freeze
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(request) ⇒ HandshakeRequest
constructor
A new instance of HandshakeRequest.
- #key ⇒ Object
-
#upgrade? ⇒ Boolean
Verify if request contains upgrade to websocket demand.
-
#valid_protocol? ⇒ Boolean
Verify if request contains a valid protocol request.
-
#valid_version? ⇒ Boolean
Verify if request contains a valid version of websocket protocol.
Constructor Details
#initialize(request) ⇒ HandshakeRequest
Returns a new instance of HandshakeRequest.
15 16 17 18 19 20 21 22 |
# File 'lib/web_socket_rb/wrapper/handshake_request.rb', line 15 def initialize(request) @request = request @headers = {} @version = '1.1' @path = '/' convert_request_to_hash end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
13 14 15 |
# File 'lib/web_socket_rb/wrapper/handshake_request.rb', line 13 def headers @headers end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
13 14 15 |
# File 'lib/web_socket_rb/wrapper/handshake_request.rb', line 13 def path @path end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
13 14 15 |
# File 'lib/web_socket_rb/wrapper/handshake_request.rb', line 13 def version @version end |
Instance Method Details
#key ⇒ Object
41 42 43 |
# File 'lib/web_socket_rb/wrapper/handshake_request.rb', line 41 def key headers['Sec-WebSocket-Key'].to_s end |
#upgrade? ⇒ Boolean
Verify if request contains upgrade to websocket demand
25 26 27 |
# File 'lib/web_socket_rb/wrapper/handshake_request.rb', line 25 def upgrade? headers['Connection'] == 'Upgrade' && headers['Upgrade'] == 'websocket' end |
#valid_protocol? ⇒ Boolean
Verify if request contains a valid protocol request
35 36 37 38 39 |
# File 'lib/web_socket_rb/wrapper/handshake_request.rb', line 35 def valid_protocol? protocols = headers['Sec-WebSocket-Protocol'].to_s protocols = protocols.split(',').map(&:strip) protocols.empty? || protocols.include?(PROTOCOL) end |
#valid_version? ⇒ Boolean
Verify if request contains a valid version of websocket protocol
30 31 32 |
# File 'lib/web_socket_rb/wrapper/handshake_request.rb', line 30 def valid_version? headers['Sec-WebSocket-Version'].to_i == VERSION end |