Class: WebSocket::Handshake::Client

### Home Classes Methods

### In Files

- lib/websocket/handshake/client.rb

### Parent

WebSocket::Handshake::Base

### Methods

- ::new
- #<<
- #should_respond?

### Class/Module Index

Quicksearch

- WebSocket
- WebSocket::Error
- WebSocket::Error::Frame
- WebSocket::Error::Frame::ControlFramePayloadTooLong
- WebSocket::Error::Frame::DataFrameInsteadContinuation
- WebSocket::Error::Frame::FragmentedControlFrame
- WebSocket::Error::Frame::Invalid
- WebSocket::Error::Frame::InvalidPayloadEncoding
- WebSocket::Error::Frame::MaskTooShort
- WebSocket::Error::Frame::ReservedBitUsed
- WebSocket::Error::Frame::TooLong
- WebSocket::Error::Frame::UnexpectedContinuationFrame
- WebSocket::Error::Frame::UnknownCloseCode
- WebSocket::Error::Frame::UnknownFrameType
- WebSocket::Error::Frame::UnknownOpcode
- WebSocket::Error::Frame::UnknownVersion
- WebSocket::Error::Handshake
- WebSocket::Error::Handshake::GetRequestRequired
- WebSocket::Error::Handshake::InvalidAuthentication
- WebSocket::Error::Handshake::InvalidHeader
- WebSocket::Error::Handshake::InvalidStatusCode
- WebSocket::Error::Handshake::NoHostProvided
- WebSocket::Error::Handshake::UnknownVersion
- WebSocket::ExceptionHandler
- WebSocket::ExceptionHandler::ClassMethods
- WebSocket::Frame
- WebSocket::Frame::Base
- WebSocket::Frame::Data
- WebSocket::Frame::Handler
- WebSocket::Frame::Handler::Base
- WebSocket::Frame::Handler::Handler03
- WebSocket::Frame::Handler::Handler04
- WebSocket::Frame::Handler::Handler05
- WebSocket::Frame::Handler::Handler07
- WebSocket::Frame::Handler::Handler75
- WebSocket::Frame::Incoming
- WebSocket::Frame::Incoming::Client
- WebSocket::Frame::Incoming::Server
- WebSocket::Frame::Outgoing
- WebSocket::Frame::Outgoing::Client
- WebSocket::Frame::Outgoing::Server
- WebSocket::Handshake
- WebSocket::Handshake::Base
- WebSocket::Handshake::Client
- WebSocket::Handshake::Handler
- WebSocket::Handshake::Handler::Base
- WebSocket::Handshake::Handler::Client
- WebSocket::Handshake::Handler::Client01
- WebSocket::Handshake::Handler::Client04
- WebSocket::Handshake::Handler::Client11
- WebSocket::Handshake::Handler::Client75
- WebSocket::Handshake::Handler::Client76
- WebSocket::Handshake::Handler::Server
- WebSocket::Handshake::Handler::Server04
- WebSocket::Handshake::Handler::Server75
- WebSocket::Handshake::Handler::Server76
- WebSocket::Handshake::Server

No matching classes.

# WebSocket::Handshake::Client

Construct or parse a client WebSocket handshake.

@example

    @handshake = WebSocket::Handshake::Client.new(url: 'ws://example.com')

    # Create request
    @handshake.to_s # GET /demo HTTP/1.1
                    # Upgrade: websocket
                    # Connection: Upgrade
                    # Host: example.com
                    # Origin: http://example.com
                    # Sec-WebSocket-Version: 13
                    # Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==

    # Parse server response
    @handshake << <<EOF
    HTTP/1.1 101 Switching Protocols\r
    Upgrade: websocket\r
    Connection: Upgrade\r
    Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r
    \r
    EOF

    # All data received?
    @handshake.finished?

    # No parsing errors?
    @handshake.valid?

### Constants

FIRST_LINE

### Attributes

headers[R]
origin[R]

### Public Class Methods

new(args = {}) click to toggle source

Initialize new WebSocket Client

@param [Hash] args Arguments for client

@option args [String] :host Host of request. Required if no :url param was provided. @option args [String] :origin Origin of request. Optional, should be used mostly by browsers. Default: nil @option args [String] :path Path of request. Should start with '/'. Default: '/' @option args [Integer] :port Port of request. Default: nil @option args [String] :query. Query for request. Should be in format "aaa=bbb&ccc=ddd" @option args [Boolean] :secure Defines protocol to use. If true then wss://, otherwise ws://. This option will not change default port - it should be handled by programmer. @option args [String] :url 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. @option args [String] :uri Alias to :url @option args [Integer] :version Version of WebSocket to use. Default: 13 (this is version from RFC) @option args [Hash] :headers HTTP headers to use in the handshake

@example

    Websocket::Handshake::Client.new(url: "ws://example.com/path?query=true")

    # File lib/websocket/handshake/client.rb, line 55
    def initialize(args = {})
      super

      @version = args[:version] || DEFAULT_VERSION
      @origin = args[:origin]
      @headers = args[:headers] || {}

      if args[:url] || args[:uri]
        uri     = URI.parse(args[:url] || args[:uri])
        @secure = (uri.scheme == 'wss')
        @host   = uri.host
        @port   = uri.port
        @path   = uri.path
        @query  = uri.query
      end

      @secure = args[:secure] if args[:secure]
      @host   = args[:host]   if args[:host]
      @port   = args[:port]   if args[:port]
      @path   = args[:path]   if args[:path]
      @query  = args[:query]  if args[:query]

      @path   = '/'           if @path.nil? || @path.empty?

      raise WebSocket::Error::Handshake::NoHostProvided unless @host

      include_version
    end

### Public Instance Methods

<<(data) click to toggle source

Add text of response from Server. This method will parse content immediately and update state and error(if neccessary)

@param [String] data Data to add

@example

    @handshake << <<EOF
    HTTP/1.1 101 Switching Protocols
    Upgrade: websocket
    Connection: Upgrade
    Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=

    EOF

    # File lib/websocket/handshake/client.rb, line 97
    def <<(data)
      @data << data
      if parse_data

      end
    end

should_respond?() click to toggle source

Should send content to server after finished parsing? @return [Boolean] false

    # File lib/websocket/handshake/client.rb, line 107
    def should_respond?
      false
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.