Wrench\Protocol\Rfc6455Protocol¶
-
class
Rfc6455Protocol
¶ This is the version of websockets used by Chrome versions 17 through 19.
-
constant
SCHEME_WEBSOCKET
¶ Relevant schemes
-
constant
HEADER_HOST
¶ HTTP headers
-
constant
HTTP_SWITCHING_PROTOCOLS
¶ HTTP error statuses
-
constant
CLOSE_NORMAL
¶ Close statuses
-
constant
TYPE_CONTINUATION
¶ Frame types
- %x0 denotes a continuation frame
- %x1 denotes a text frame %x2 denotes a binary frame %x3-7 are reserved for further non-control frames %x8 denotes a connection close %x9 denotes a ping %xA denotes a pong %xB-F are reserved for further control frames
-
constant
MAGIC_GUID
¶ Magic GUID
Used in the WebSocket accept header
-
constant
UPGRADE_VALUE
¶ - The request MUST contain an |Upgrade| header field whose value
- MUST include the “websocket” keyword.
-
constant
CONNECTION_VALUE
¶ - The request MUST contain a |Connection| header field whose value
- MUST include the “Upgrade” token.
-
constant
REQUEST_LINE_FORMAT
¶ Request line format
-
constant
REQUEST_LINE_REGEX
¶ Request line regex
Used for parsing requested path
-
constant
RESPONSE_LINE_FORMAT
¶ Response line format
-
constant
HEADER_LINE_FORMAT
¶ Header line format
-
property
schemes
¶ protected array<string>
Valid schemes
-
property
closeReasons
¶ array<int
Close status codes
-
property
frameTypes
¶ array<string
Frame types
-
property
httpResponses
¶ array<int
HTTP errors
-
getVersion
()¶
-
acceptsVersion
($version)¶ This is our most recent protocol class
Parameters: - $version –
-
getPayload
()¶
-
generateKey
()¶ Generates a key suitable for use in the protocol
This base implementation returns a 16-byte (128 bit) random key as a binary string.
Returns: string
-
getRequestHandshake
($uri, $key, $origin, $headers = array())¶ Gets request handshake string
The leading line from the client follows the Request-Line format. The leading line from the server follows the Status-Line format. The Request-Line and Status-Line productions are defined in [RFC2616].
An unordered set of header fields comes after the leading line in both cases. The meaning of these header fields is specified in Section 4 of this document. Additional header fields may also be present, such as cookies [RFC6265]. The format and parsing of headers is as defined in [RFC2616].
Parameters: - $uri (string) – WebSocket URI, e.g. ws://example.org:8000/chat
- $key (string) – 16 byte binary string key
- $origin (string) – Origin of the request
- $headers –
Returns: string
-
getResponseHandshake
($key, $headers = array())¶ Gets a handshake response body
Parameters: - $key (string) –
- $headers (array) –
-
getResponseError
($e, $headers = array())¶ Gets a response to an error in the handshake
Parameters: - $e (int|Exception) – Exception or HTTP error
- $headers (array) –
-
getHttpResponse
($status, $headers = array())¶ Gets an HTTP response
Parameters: - $status (int) –
- $headers (array) –
-
validateResponseHandshake
($response, $key)¶ Parameters: - $response (unknown_type) –
- $key (unknown_type) –
Returns: boolean
-
getEncodedHash
($key)¶ Gets an encoded hash for a key
Parameters: - $key (string) –
Returns: string
-
validateRequestHandshake
($request)¶ Validates a request handshake
Parameters: - $request (string) –
-
getCloseFrame
($e)¶ Gets a suitable WebSocket close frame
Parameters: - $e (Exception|int) –
-
validateUri
($uri)¶ Validates a WebSocket URI
Parameters: - $uri (string) –
Returns: array(string $scheme, string $host, int $port, string $path)
-
validateSocketUri
($uri)¶ Validates a socket URI
Parameters: - $uri (string) –
Returns: array(string $scheme, string $host, string $port)
-
validateOriginUri
($origin)¶ Validates an origin URI
Parameters: - $origin (string) –
Returns: string
-
validateRequestLine
($line)¶ Validates a request line
Parameters: - $line (string) –
-
getAcceptValue
($encoded_key)¶ Gets the expected accept value for a handshake response
Note that the protocol calls for the base64 encoded value to be hashed, not the original 16 byte random key.
Parameters: - $encoded_key –
-
getHeaders
($response, $request_line = null)¶ Gets the headers from a full response
Parameters: - $response (string) –
- $request_line –
Returns: array()
-
getRequestHeaders
($response)¶ Gets request headers
Parameters: - $response (string) –
Returns: array<string, array<string>> The request line, and an array of headers
-
validateScheme
($scheme)¶ Validates a scheme
Parameters: - $scheme (string) –
Returns: string Underlying scheme
-
getDefaultRequestHeaders
($host, $key, $origin)¶ Gets the default request headers
Parameters: - $host (string) –
- $key (string) –
- $origin (string) –
Returns: multitype:unknown string NULL
-
getSuccessResponseHeaders
($key)¶ Gets the default response headers
Parameters: - $key (string) –
-
getPort
($scheme)¶ Gets the default port for a scheme
By default, the WebSocket Protocol uses port 80 for regular WebSocket connections and port 443 for WebSocket connections tunneled over Transport Layer Security
Parameters: - $scheme –
Returns: int
-
constant