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=
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
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 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
Generated with the Darkfish Rdoc Generator 2.