Parent

WebSocket::Handshake::Base

@abstract Subclass and override to implement custom handshakes

Constants

HEADER

Attributes

error[R]
host[R]
path[R]
port[R]
query[R]
secure[R]
state[R]
version[R]

Public Class Methods

new(args = {}) click to toggle source

Initialize new WebSocket Handshake and set it's state to :new

# File lib/websocket/handshake/base.rb, line 10
def initialize(args = {})
  @state = :new

  @data = ""
  @headers = {}
end

Public Instance Methods

<<(data) click to toggle source

@abstract Add data to handshake

# File lib/websocket/handshake/base.rb, line 18
def <<(data)
  raise NotImplementedError
end
finished?() click to toggle source

Is parsing of data finished? @return [Boolena] True if request was completely parsed or error occured. False otherwise

# File lib/websocket/handshake/base.rb, line 37
def finished?
  @state == :finished || @state == :error
end
inspect() click to toggle source

Recreate inspect as to_s was overwritten

# 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() click to toggle source

Data left from parsing. Sometimes data that doesn't belong to handshake are added - use this method to retrieve them. @return [String] String if some data are available. Nil otherwise

# File lib/websocket/handshake/base.rb, line 54
def leftovers
  @leftovers.split("\n", reserved_leftover_lines + 1)[reserved_leftover_lines]
end
should_respond?() click to toggle source

@abstract Should send data after parsing is finished?

# File lib/websocket/handshake/base.rb, line 48
def should_respond?
  raise NotImplementedError
end
to_s() click to toggle source

Return textual representation of handshake request or response @return [String] text of response

# File lib/websocket/handshake/base.rb, line 24
def to_s
  ""
end
uri() click to toggle source

URI of request. @return [String] Full URI with protocol @example

@handshake.uri #=> "ws://example.com/path?query=true"
# 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?() click to toggle source

Is parsed data valid? @return [Boolean] False if some errors occured. Reason for error could be found in error method

# File lib/websocket/handshake/base.rb, line 43
def valid?
  finished? && @error == nil
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.