WebSocket::Handshake::Server

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=

Constants

PATH

Public Class Methods

new(args = {}) click to toggle source

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)
# File lib/websocket/handshake/server.rb, line 42
def initialize(args = {})
  super
  @secure = !!args[:secure]
end

Public Instance Methods

<<(data) click to toggle source

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
# File lib/websocket/handshake/server.rb, line 62
def <<(data)
  @data << data
  if parse_data
    set_version
  end
end
host() click to toggle source

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

# File lib/websocket/handshake/server.rb, line 77
def host
  @headers["host"].to_s.split(":")[0].to_s
end
port() click to toggle source

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

# File lib/websocket/handshake/server.rb, line 83
def port
  @headers["host"].to_s.split(":")[1]
end
should_respond?() click to toggle source

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

# File lib/websocket/handshake/server.rb, line 71
def should_respond?
  true
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.