Protocol::WebSocket::XS::ConnectResponse - Websocket server response for connection request
use Protocol::WebSocket::XS; # server creates connect responses my $response = Protocol::WebSocket::XS::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;
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
101 Switching Protocols
Sec-WebSocket-Extensions
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:
new()
Identifies application specific communication protocol.
See rfc6455 (look for Sec-WebSocket-Protocol).
Sec-WebSocket-Protocol
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::XS::ServerParser.
Get/set key hash, i.e. Sec-WebSocket-Accept header.
Sec-WebSocket-Accept
Returns value of Sec-WebSocket-Version header in response.
Sec-WebSocket-Version
Get/set available websocket extensions in response. Currently only permessage-deflate is supported.
permessage-deflate
$response->ws_extensions([['permessage-deflate' => { 'client_max_window_bits' => '15' }]]);
See Protocol::WebSocket::XS::Parser for all available deflate options.
Get/set websocket protocol identity (i.e. Sec-WebSocket-Protocol header).
XS::ErrorCode object which represents Perl API for convenient C++ std::error_code subsystem. Possible errors are described in Protocol::WebSocket::XS::Error, Protocol::HTTP::Error.
std::error_code
if ($response->error) { # handle it }
Protocol::WebSocket::XS
Protocol::WebSocket::XS::ConnectRequest
Protocol::WebSocket::XS::ClientParser
Protocol::WebSocket::XS::HTTPRequest
Protocol::WebSocket::XS::ServerParser
To install Protocol::WebSocket::XS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Protocol::WebSocket::XS
CPAN shell
perl -MCPAN -e shell install Protocol::WebSocket::XS
For more information on module installation, please visit the detailed CPAN module installation guide.