Class: Mongrel2::WebSocket::ClientHandshake

Inherits:
HTTPRequest show all
Includes:
Constants
Defined in:
lib/mongrel2/websocket.rb

Overview

The client (request) handshake for a WebSocket opening handshake.

Constant Summary

Constants included from Constants

Mongrel2::WebSocket::Constants::CLOSE_ABNORMAL_STATUS, Mongrel2::WebSocket::Constants::CLOSE_BAD_DATA, Mongrel2::WebSocket::Constants::CLOSE_BAD_DATA_TYPE, Mongrel2::WebSocket::Constants::CLOSE_EXCEPTION, Mongrel2::WebSocket::Constants::CLOSE_GOING_AWAY, Mongrel2::WebSocket::Constants::CLOSE_MESSAGE_TOO_LARGE, Mongrel2::WebSocket::Constants::CLOSE_MISSING_EXTENSION, Mongrel2::WebSocket::Constants::CLOSE_MISSING_STATUS, Mongrel2::WebSocket::Constants::CLOSE_NORMAL, Mongrel2::WebSocket::Constants::CLOSE_POLICY_VIOLATION, Mongrel2::WebSocket::Constants::CLOSE_PROTOCOL_ERROR, Mongrel2::WebSocket::Constants::CLOSE_RESERVED, Mongrel2::WebSocket::Constants::CLOSE_TLS_ERROR, Mongrel2::WebSocket::Constants::CLOSING_STATUS_DESC, Mongrel2::WebSocket::Constants::DEFAULT_CHUNKSIZE, Mongrel2::WebSocket::Constants::FIN_FLAG, Mongrel2::WebSocket::Constants::OPCODE, Mongrel2::WebSocket::Constants::OPCODE_BITMASK, Mongrel2::WebSocket::Constants::OPCODE_CONTROL_MASK, Mongrel2::WebSocket::Constants::OPCODE_NAME, Mongrel2::WebSocket::Constants::RSV1_FLAG, Mongrel2::WebSocket::Constants::RSV2_FLAG, Mongrel2::WebSocket::Constants::RSV3_FLAG, Mongrel2::WebSocket::Constants::RSV_FLAG_MASK

Constants inherited from HTTPRequest

HTTPRequest::HANDLED_HTTP_METHODS

Instance Attribute Summary

Attributes inherited from Request

#body, #conn_id, #headers, #path, #raw, #sender_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from HTTPRequest

#content_encoding, #content_encoding=, #content_length, #content_type, #content_type=, #keepalive?, #scheme, #ssl?

Methods inherited from Request

#extended_reply?, #initialize, #inspect, #is_disconnect?, parse, register_request_type, #remote_ip, #server_chroot, #socket_id, subclass_for_method, #upload_done?, #upload_headers_match?, #upload_started?, #uploaded_file, #valid_upload?

Constructor Details

This class inherits a constructor from Mongrel2::Request

Class Method Details

.response_classObject

Override the type of response returned by this request type. Since websocket handshakes are symmetrical, responses are just new Mongrel2::WebSocket::Handshakes with the same Mongrel2 sender and connection IDs.



258
259
260
# File 'lib/mongrel2/websocket.rb', line 258

def self::response_class
  return Mongrel2::WebSocket::ServerHandshake
end

Instance Method Details

#protocolsObject

The list of protocols in the handshake’s Sec-WebSocket-Protocol header as an Array of Strings.



269
270
271
# File 'lib/mongrel2/websocket.rb', line 269

def protocols
  return ( self.headers.sec_websocket_protocol || '' ).split( /\s*,\s*/ )
end

#response(protocol = nil) ⇒ Object

Create a Mongrel2::WebSocket::Handshake that will respond to the same server/connection as the receiver.



276
277
278
279
280
281
282
283
284
285
286
# File 'lib/mongrel2/websocket.rb', line 276

def response( protocol=nil )
  @response = super() unless @response
  if protocol
    raise Mongrel2::WebSocket::HandshakeError,
      "attempt to create a %s handshake which isn't supported by the client." %
      [ protocol ] unless self.protocols.include?( protocol.to_s )
    @response.protocols = protocol
  end

  return @response
end