Class WebSocket::Handshake::Server
In: lib/websocket/handshake/server.rb
Parent: Base

Construct or parse a server WebSocket handshake.

@example

  handshake = WebSocket::Handshake::Server.new

  # Parse client request
  @handshake << <<EOF
  GET /demo HTTP/1.1\r
  Upgrade: websocket\r
  Connection: Upgrade\r
  Host: example.com\r
  Sec-WebSocket-Origin: http://example.com\r
  Sec-WebSocket-Version: 13\r
  Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r
  \r
  EOF

  # All data received?
  @handshake.finished?

  # No parsing errors?
  @handshake.valid?

  # Create response
  @handshake.to_s # HTTP/1.1 101 Switching Protocols
                  # Upgrade: websocket
                  # Connection: Upgrade
                  # Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=

Methods

<<   host   new   port   should_respond?  

Constants

PATH = /^(\w+) (\/[^\s]*) HTTP\/1\.1$/

Public Class methods

Initialize new WebSocket Server

@param [Hash] args Arguments for server

@option args [Boolean] :secure If true then server will use wss:// protocol

@example

  Websocket::Handshake::Server.new(:secure => true)

Public Instance methods

Add text of request from Client. This method will parse content immediately and update version, state and error(if neccessary)

@param [String] data Data to add

@example

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

  EOF

Host of server according to client header @return [String] host

Port of server according to client header @return [String] port

Should send content to client after finished parsing? @return [Boolean] true

[Validate]