| 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
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=
| PATH | = | %r{^(\w+) (\/[^\s]*) HTTP\/1\.1$} |
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 Origin: http://example.com Sec-WebSocket-Version: 13 Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== EOF
Parse the request from hash @param hash Hash to import data @option hash [Hash] :headers HTTP headers of request, downcased @option hash [String] :path Path for request(without host and query string) @option hash [String] :query Query string for request @option hash [String] :body Body of request(if exists)
@example
@handshake.from_hash(hash)