class WebSocket::Handshake::Client


@handshake.valid?
# No parsing errors?
@handshake.finished?
# All data received?
EOF
r
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=r
Connection: Upgrader
Upgrade: websocketr
HTTP/1.1 101 Switching Protocolsr
@handshake << <<EOF
# Parse server response
# Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
# Sec-WebSocket-Version: 13
# Origin: example.com<br># Host: example.com
# Connection: Upgrade
# Upgrade: websocket
@handshake.to_s # GET /demo HTTP/1.1
# Create request
@handshake = WebSocket::Handshake::Client.new(url: ‘ws://example.com’)
@example
Construct or parse a client WebSocket handshake.

def <<(data)

Parameters:
  • data (String) -- Data to add
def <<(data)
  super
  parse_data
end

def include_version

Returns:
  • (Boolean) - false if protocol number is unknown, otherwise true
def include_version
  @handler = case @version
             when 75 then Handler::Client75.new(self)
             when 76, 0 then Handler::Client76.new(self)
             when 1..3  then Handler::Client01.new(self)
             when 4..10 then Handler::Client04.new(self)
             when 11..17 then Handler::Client11.new(self)
             else raise WebSocket::Error::Handshake::UnknownVersion
             end
end

def initialize(args = {})

Options Hash: (**args)
  • :headers (Hash) -- HTTP headers to use in the handshake
  • :version (Integer) -- Version of WebSocket to use. Default: 13 (this is version from RFC)
  • :protocols (Array) -- An array of supported sub-protocols
  • :uri (String) -- Alias to :url
  • :url (String) -- URL of request. Must by in format like ws://example.com/path?query=true. Every part of this url will be overriden by more specific arguments.
  • :secure (Boolean) -- Defines protocol to use. If true then wss://, otherwise ws://. This option will not change default port - it should be handled by programmer.
  • :query. (String) -- Query for request. Should be in format "aaa=bbb&ccc=ddd"
  • :port (Integer) -- Port of request. Default: nil
  • :path (String) -- Path of request. Should start with '/'. Default: '/'
  • :origin (String) -- Origin of request. Optional, should be used mostly by browsers. Default: nil
  • :host (String) -- Host of request. Required if no :url param was provided.

Parameters:
  • args (Hash) -- Arguments for client
def initialize(args = {})
  super
  if @url || @uri
    uri = URI.parse(@url || @uri)
    @secure ||= (uri.scheme == 'wss')
    @host ||= uri.host
    @port ||= uri.port || default_port
    @path ||= uri.path
    @query ||= uri.query
  end
  @path = '/' if @path.nil? || @path.empty?
  @version ||= DEFAULT_VERSION
  raise WebSocket::Error::Handshake::NoHostProvided unless @host
  include_version
end

def parse_first_line(line)

Returns:
  • (Boolean) - True if parsed correctly. False otherwise

Parameters:
  • line (String) -- Line to parse
def parse_first_line(line)
  line_parts = line.match(FIRST_LINE)
  raise WebSocket::Error::Handshake::InvalidHeader unless line_parts
  status = line_parts[1]
  raise WebSocket::Error::Handshake::InvalidStatusCode unless status == '101'
end

def should_respond?

Returns:
  • (Boolean) - false
def should_respond?
  false
end