NAME
Net::WebSocket::Handshake::Extension - WebSocket extension handshake
SYNOPSIS
#Returns a list of instances of this class
my @exts = Net::WebSocket::Handshake::Extension->parse_string(
$value_of_sec_websocket_extensions
);
my $ext = Net::WebSocket::Handshake::Extension->new(
'extension-name',
param1 => 'value1',
#...
);
my $name = $ext->token(); #e.g., 'extension-name'
my @params = $ext->parameters();
#@others is an array of instances of this class
my $str = $ext->to_string(@others);
DESCRIPTION
This module handles the handshake component of WebSocket extensions: specifically, it translates between an extension name and parameters as an object and as actually represented in the values of HTTP headers.
It’s flexible enough that you can determine how you want extensions divided among multiple Sec-WebSocket-Extensions
headers.
Note that a server, as per the protocol specification, “MUST NOT” include more than one Sec-WebSocket-Extensions
header in its handshake response.
METHODS
@objects = CLASS->parse_string( HEADER_VALUE )
Parses the value of the Sec-WebSocket-Extensions
header (i.e., HEADER_VALUE) into one or more instances of this class.
CLASS->new( NAME, PARAMS_KV )
Returns an instance of the class, with NAME as the token()
value and PARAMS_KV as parameters()
. Probably less useful than parse_string()
.
OBJ->token()
Returns the token as given in the Sec-WebSocket-Extensions
header.
%params = OBJ->parameters()
Returns the parameters as given in the Sec-WebSocket-Extensions
header. The parameters are a list of key/value pairs, suitable for representation as a hash. Parameters that have no value (e.g., the permessage-deflate
extension’s client_no_context_takeover
parameter) are given undef as a Perl value.
OBJ->to_string( OTHER_EXTENSIONS )
Returns a string that represents the extension (and any others) as a Sec-WebSocket-Extensions
header value. Other extensions are to be given as instances of this class.