class Mongrel2::WebSocket::ServerHandshake
The server (response) handshake for a WebSocket
opening handshake.
Public Class Methods
from_request( handshake )
click to toggle source
Create a server handshake frame from the given client handshake
.
Calls superclass method
Mongrel2::Response::from_request
# File lib/mongrel2/websocket.rb, line 295 def self::from_request( handshake ) self.log.debug "Creating the server handshake for client handshake %p" % [ handshake ] response = super response.body.truncate( 0 ) # Mongrel2 puts the negotiated key in the body of the request response.headers.sec_websocket_accept = handshake.body.read # Set up the other typical server handshake values response.status = HTTP::SWITCHING_PROTOCOLS response.header.upgrade = 'websocket' response.header.connection = 'Upgrade' return response end
Public Instance Methods
protocols()
click to toggle source
The list of protocols in the handshake's Sec-WebSocket-Protocol header as an Array of Strings.
# File lib/mongrel2/websocket.rb, line 314 def protocols return ( self.headers.sec_websocket_protocol || '' ).split( /\s*,\s*/ ) end
protocols=( new_protocols )
click to toggle source
Set the list of protocols in the handshake's Sec-WebSocket-Protocol header.
# File lib/mongrel2/websocket.rb, line 320 def protocols=( new_protocols ) value = Array( new_protocols ).join( ', ' ) self.headers.sec_websocket_protocol = value end