NAME
Protocol::WebSocket::Fast::ConnectResponse - Websocket server response for connection request
SYNOPSIS
use Protocol::WebSocket::Fast;
# server creates connect responses
my $response = Protocol::WebSocket::Fast::ConnectResponse->new({
body => '...',
headers => { 'Cache-Control' => 'no-cache'},
ws_protocol => "chat",
ws_extensions => [["ext1"], ["ext2", {arg1 => 1}]],
});
# client parses connect responses
$response = $client_parser->connect($data);
$response->body;
$response->ws_protocol;
$response->ws_extensions;
$response->ws_accept_key;
$response->ws_version;
$response->error;
DESCRIPTION
A response that is sent by websocket server to client. This class extends Protocol::HTTP::Response with websocket-related details, so all methods of Protocol::HTTP::Response also apply.
A successful response is 101 Switching Protocols
and contains selected subset of server-supported extensions and their options, initially proposed by client in the request if they match server-configuration, e.g. Sec-WebSocket-Extensions
METHODS
new([\%params])
Creates new connect response object from params (or empty, if no params specified).
Parameters are everything that Protocol::HTTP::Response's new()
supports plus the following:
- ws_protocol
-
Identifies application specific communication protocol.
See rfc6455 (look for
Sec-WebSocket-Protocol
). - ws_extensions => \@extensions
-
Additional extensions and their options, which has been offered by client-side and server-side aggrees to use. The extensions, which are provided by the module and enabled by user (default), will be added automatically by Protocol::WebSocket::Fast::ServerParser.
ws_accept_key([$key])
Get/set key hash, i.e. Sec-WebSocket-Accept
header.
ws_version()
Returns value of Sec-WebSocket-Version
header in response.
ws_extensions([\@extensions])
Get/set available websocket extensions in response. Currently only permessage-deflate
is supported.
$response->ws_extensions([['permessage-deflate' => { 'client_max_window_bits' => '15' }]]);
See Protocol::WebSocket::Fast::Parser for all available deflate options.
ws_protocol([$string])
Get/set websocket protocol identity (i.e. Sec-WebSocket-Protocol
header).
error()
XS::ErrorCode object which represents Perl API for convenient C++ std::error_code
subsystem. Possible errors are described in Protocol::WebSocket::Fast::Error, Protocol::HTTP::Error.
if ($response->error) {
# handle it
}
SEE ALSO
Protocol::WebSocket::Fast::ConnectRequest
Protocol::WebSocket::Fast::ClientParser