NAME

Net::WebSocket::Handshake::Server

SYNOPSIS

my $hsk = Net::WebSocket::Handshake::Server->new(

    #optional
    subprotocols => [ 'echo', 'haha' ],

    #optional
    extensions => \@extension_objects,
);

$hsk->valid_method_or_die( $http_method );  #optional

$hsk->consume_headers(@headers_kv_pairs);

my $resp_hdr = $hsk->to_string();

DESCRIPTION

This class implements WebSocket handshake logic for a server. It handles the basics of handshaking and, optionally, subprotocol and extension negotiation.

CLASS->new( %OPTS )

Returns an instance of this class. %OPTS is as described in the base class; there are no options specific to this class.

OBJ->valid_protocol_or_die( PROTOCOL )

Throws an exception if the given PROTOCOL isn’t the HTTP protocol (HTTP/1.1) that WebSocket requires for all requests.

You only need this if if you’re not using a request-parsing interface that’s compatible with HTTP::Request; otherwise, Net::WebSocket::HTTP_R’s handshake_consume_request() function will do this (and other niceties) for you.

OBJ->valid_method_or_die( METHOD )

Throws an exception if the given METHOD isn’t the HTTP method (GET) that WebSocket requires for all requests.

As with valid_protocol_or_die(), Net::WebSocket::HTTP_R might call this method for you.

LEGACY INTERFACE: SYNOPSIS

#...Parse the request’s headers yourself...

my $hsk = Net::WebSocket::Handshake::Server->new(

    #base 64, gotten from request
    key => '..',

    #optional - same as in non-legacy interface
    subprotocols => [ 'echo', 'haha' ],

    #optional, instances of Net::WebSocket::Handshake::Extension
    extensions => \@extension_objects,
);

#Note the need to conclude the header text manually.
print $hsk->create_header_text() . "\x0d\x0a";