Class: WebSocket::Handshake::Base

### Home Classes Methods

### In Files

- lib/websocket/handshake/base.rb

### Parent

Object

### Methods

- ::new
- #<<
- #finished?
- #inspect
- #leftovers
- #should_respond?
- #to_s
- #uri
- #valid?

### Included Modules

- WebSocket::ExceptionHandler

### 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::Base

@abstract Subclass and override to implement custom handshakes

### Constants

HEADER

### Attributes

headers[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 11
    def initialize(args = {})
      @state = :new
      @handler = nil

      @data = ''
      @headers = {}
    end

### Public Instance Methods

<<(data) click to toggle source

@abstract Add data to handshake

    # File lib/websocket/handshake/base.rb, line 20
    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 40
    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 32
    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 58
    def leftovers
      (@leftovers.to_s.split("\n", reserved_leftover_lines + 1)[reserved_leftover_lines] || "").strip
    end

should_respond?() click to toggle source

@abstract Should send data after parsing is finished?

    # File lib/websocket/handshake/base.rb, line 52
    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 26
    def to_s
      @handler ? @handler.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 66
    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 46
    def valid?
      finished? && @error == nil && @handler && @handler.valid?
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.