Class: Mongrel2::WebSocket::ServerHandshake
- Inherits:
-
HTTPResponse
- Object
- Response
- HTTPResponse
- Mongrel2::WebSocket::ServerHandshake
- Includes:
- Constants
- Defined in:
- lib/mongrel2/websocket.rb
Overview
The server (response) handshake for a WebSocket opening handshake.
Constant Summary
Constants included from Constants
Constants::CLOSE_ABNORMAL_STATUS, Constants::CLOSE_BAD_DATA, Constants::CLOSE_BAD_DATA_TYPE, Constants::CLOSE_EXCEPTION, Constants::CLOSE_GOING_AWAY, Constants::CLOSE_MESSAGE_TOO_LARGE, Constants::CLOSE_MISSING_EXTENSION, Constants::CLOSE_MISSING_STATUS, Constants::CLOSE_NORMAL, Constants::CLOSE_POLICY_VIOLATION, Constants::CLOSE_PROTOCOL_ERROR, Constants::CLOSE_RESERVED, Constants::CLOSE_TLS_ERROR, Constants::CLOSING_STATUS_DESC, Constants::DEFAULT_CHUNKSIZE, Constants::FIN_FLAG, Constants::OPCODE, Constants::OPCODE_BITMASK, Constants::OPCODE_CONTROL_MASK, Constants::OPCODE_NAME, Constants::RSV1_FLAG, Constants::RSV2_FLAG, Constants::RSV3_FLAG, Constants::RSV_FLAG_MASK
Constants inherited from HTTPResponse
HTTPResponse::DEFAULT_CONTENT_TYPE, HTTPResponse::EOL, HTTPResponse::STATUS_LINE_FORMAT
Constants included from Constants
Constants::DATA_DIR, Constants::DEFAULT_CONFIG_SCRIPT, Constants::DEFAULT_CONFIG_URI, Constants::DEFAULT_CONTROL_SOCKET, Constants::MAX_BROADCAST_IDENTS
Constants inherited from Response
Instance Attribute Summary
Attributes inherited from HTTPResponse
Attributes inherited from Response
#body, #chunksize, #conn_id, #extended_reply_data, #extended_reply_filter, #request, #sender_id
Class Method Summary collapse
-
.from_request(handshake) ⇒ Object
Create a server handshake frame from the given client
handshake
.
Instance Method Summary collapse
-
#protocols ⇒ Object
The list of protocols in the handshake’s Sec-WebSocket-Protocol header as an Array of Strings.
-
#protocols=(new_protocols) ⇒ Object
Set the list of protocols in the handshake’s Sec-WebSocket-Protocol header.
Methods inherited from HTTPResponse
#bodiless?, #content_type, #content_type=, #get_content_length, #handled?, #header_data, #initialize, #keepalive=, #keepalive?, #normalized_headers, #reset, #set_defaults, #status_category, #status_is_clienterror?, #status_is_informational?, #status_is_redirect?, #status_is_servererror?, #status_is_successful?, #status_line, #to_s
Methods inherited from Response
#<<, #each_chunk, #extend_reply_with, #extended_reply?, #initialize, #inspect, #puts, #socket_id, #to_s
Constructor Details
This class inherits a constructor from Mongrel2::HTTPResponse
Class Method Details
.from_request(handshake) ⇒ Object
Create a server handshake frame from the given client handshake
.
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/mongrel2/websocket.rb', line 296 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 |
Instance Method Details
#protocols ⇒ Object
The list of protocols in the handshake’s Sec-WebSocket-Protocol header as an Array of Strings.
315 316 317 |
# File 'lib/mongrel2/websocket.rb', line 315 def protocols return ( self.headers.sec_websocket_protocol || '' ).split( /\s*,\s*/ ) end |
#protocols=(new_protocols) ⇒ Object
Set the list of protocols in the handshake’s Sec-WebSocket-Protocol header.
321 322 323 324 |
# File 'lib/mongrel2/websocket.rb', line 321 def protocols=( new_protocols ) value = Array( new_protocols ).join( ', ' ) self.headers.sec_websocket_protocol = value end |