NAME

Protocol::WebSocket::Fast::ServerParser - Server-side websocket parser

SYNOPSIS

use Protocol::WebSocket::Fast;

my $server  = Protocol::WebSocket::Fast::ServerParser->new;
my $request = $server->accept($data);

my $response_data = $request->error ? $server->accept_error : $server->accept_response;
# send $response_data to client

$server->accept_parsed;
$server->accepted;

DESCRIPTION

Server-side specialization of Protocol::WebSocket::Fast::Parser.

Methods of this class are used for accepting a logical websocket connection from client.

See Protocol::WebSocket::Fast::Parser for API after accepting a connection.

METHODS

new([\%params])

Creates new instance of parser. See Parser's configure() method for parameters description.

accept_parsed()

Returns true if server finished parsing client's connect request.

accepted()

Returns true if accept_parsed() and no errors have been met.

accept($data)

Parses client's connect request (HTTP-request).

Returns undef if more data is needed, otherwise returns Protocol::WebSocket::Fast::ConnectRequest object. In internal state sets flags whether the requests has been parsed and accepted.

Developer might inspect the request object and add application-specific checks.

In case of any errors, $request->error() will be set.

my $request = $server_parser->accept($data);

accept_response([$response])

Returns serialized successful response from server to client.

Extensions-related headers are automatically added for the build-in extensions, which where enabled by configuration (Protocol::WebSocket::Fast::Parser::configure) if request contained acceptable extension configurations.

Developer might supply customized $response with predefined headers, custom extensions, etc...

$response may be an Protocol::WebSocket::Fast::ConnectResponse object or a params hashref that its constructor supports.

my $data = $server->accept_response({
    body    => 'hello',
    headers => {hello => 'world'},
});

accept_error([$response])

Returns serialized failure response from server to client. Further communication with server is not possible, as websocket connection was not established.

Developer might supply customized $object with predefined headers, etc...

$response may be a Protocol::HTTP::Response object or a params hashref that its constructor supports.

my $data = $server->accept_error({
    code => 401,
    body => 'we are unable to process your request because ...',
});

SEE ALSO

Protocol::WebSocket::Fast

Protocol::WebSocket::Fast::ClientParser

Protocol::WebSocket::Fast::ConnectRequest

Protocol::WebSocket::Fast::ConnectResponse

Protocol::WebSocket::Fast::Parser