Class: WebSocket::Handshake::Base Abstract
- Inherits:
-
Object
- Object
- WebSocket::Handshake::Base
- Defined in:
- lib/websocket/handshake/base.rb
Overview
Subclass and override to implement custom handshakes
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#secure ⇒ Object
readonly
Returns the value of attribute secure.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #<<(data) ⇒ Object abstract
-
#finished? ⇒ Boolena
Is parsing of data finished?.
-
#initialize(args = {}) ⇒ Base
constructor
Initialize new WebSocket Handshake and set it’s state to :new.
-
#inspect ⇒ Object
Recreate inspect as #to_s was overwritten.
-
#leftovers ⇒ String
Data left from parsing.
- #should_respond? ⇒ Boolean abstract
-
#to_s ⇒ String
Return textual representation of handshake request or response.
-
#uri ⇒ String
URI of request.
-
#valid? ⇒ Boolean
Is parsed data valid?.
Constructor Details
#initialize(args = {}) ⇒ Base
Initialize new WebSocket Handshake and set it’s state to :new
10 11 12 13 14 15 |
# File 'lib/websocket/handshake/base.rb', line 10 def initialize(args = {}) @state = :new @data = "" @headers = {} end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
6 7 8 |
# File 'lib/websocket/handshake/base.rb', line 6 def error @error end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
6 7 8 |
# File 'lib/websocket/handshake/base.rb', line 6 def host @host end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/websocket/handshake/base.rb', line 6 def path @path end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
6 7 8 |
# File 'lib/websocket/handshake/base.rb', line 6 def port @port end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
6 7 8 |
# File 'lib/websocket/handshake/base.rb', line 6 def query @query end |
#secure ⇒ Object (readonly)
Returns the value of attribute secure.
6 7 8 |
# File 'lib/websocket/handshake/base.rb', line 6 def secure @secure end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
6 7 8 |
# File 'lib/websocket/handshake/base.rb', line 6 def state @state end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
6 7 8 |
# File 'lib/websocket/handshake/base.rb', line 6 def version @version end |
Instance Method Details
#<<(data) ⇒ Object
Add data to handshake
18 19 20 |
# File 'lib/websocket/handshake/base.rb', line 18 def <<(data) raise NotImplementedError end |
#finished? ⇒ Boolena
Is parsing of data finished?
37 38 39 |
# File 'lib/websocket/handshake/base.rb', line 37 def finished? @state == :finished || @state == :error end |
#inspect ⇒ Object
Recreate inspect as #to_s was overwritten
29 30 31 32 33 |
# File 'lib/websocket/handshake/base.rb', line 29 def inspect vars = self.instance_variables.map{|v| "#{v}=#{instance_variable_get(v).inspect}"}.join(", ") insp = "#{self.class}:0x%08x" % (self.__id__ * 2) "<#{insp} #{vars}>" end |
#leftovers ⇒ String
Data left from parsing. Sometimes data that doesn’t belong to handshake are added - use this method to retrieve them.
54 55 56 |
# File 'lib/websocket/handshake/base.rb', line 54 def leftovers @leftovers.split("\n", reserved_leftover_lines + 1)[reserved_leftover_lines] end |
#should_respond? ⇒ Boolean
Should send data after parsing is finished?
48 49 50 |
# File 'lib/websocket/handshake/base.rb', line 48 def should_respond? raise NotImplementedError end |
#to_s ⇒ String
Return textual representation of handshake request or response
24 25 26 |
# File 'lib/websocket/handshake/base.rb', line 24 def to_s "" end |
#uri ⇒ String
URI of request.
62 63 64 65 66 67 68 69 |
# File 'lib/websocket/handshake/base.rb', line 62 def uri uri = secure ? "wss://" : "ws://" uri << host uri << ":#{port}" if port uri << path uri << "?#{query}" if query uri end |
#valid? ⇒ Boolean
Is parsed data valid?
43 44 45 |
# File 'lib/websocket/handshake/base.rb', line 43 def valid? finished? && @error == nil end |