The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

WebSocket::Message - Common Class for Request and Response

SYNOPSIS

    use WebSocket::Request;
    my $req = WebSocket::Request->new || die( WebSocket::Request->error, "\n" );

VERSION

    v0.1.0

DESCRIPTION

This is a common class for WebSocket::Request and WebSocket::Response

METHODS

buffer

challenge

checksum

content

Alias for "buffer"

extensions

Set or get the available extensions. For example permessage-deflate to enable message compression.

You can set this to either a string or a WebSocket::Extension object if you want, for example to set the extension parameters.

See rfc6455 section 9.1 for more information on extension.

headers

headers_as_string

host

is_client_error

Returns true if the error code provided is a client error.

is_done

Returns true when the parsing is done.

is_error

Returns true when the provided code is an error

is_redirect

Returns true when the provided code is a redirect, which under the WebSocket is possible during the handshake only.

is_server_error

Returns true when the provided code is a server error.

is_success

Returns true when the provided code is a success

max_message_size

number1

number2

parse_chunk

Provided with some chunk data, and this will parse it and return a status. See "CONSTANTS" below.

Once parsing is done, you can retrieve the relevant object with "request" which returns a WebSocket::Request object or "response" which returns a WebSocket::Response object.

If an error occurs, this will returns undef and sets an error exception

protocol

Returns the http protocol used, which should always be HTTP/1.1

request

Set or get a WebSocket::Request object. This is set by "parse_chunk"

response

Set or get a WebSocket::Response object. This is set by "parse_chunk"

secure

Boolean value. True when the connection is using ssl, false otherwise.

status_message

Returns the status message provided by the other party.

subprotocol

Set or get an array object of WebSocket protocols.

Returns a Module::Generic::Array object.

See rfc6455 for more information

uri

Set or get the uri of the current request or response. Returns a URI object.

version

Set or get the WebSocket version supported.

PRIVATE METHODS

_append

Provided with some data, or a IO::Socket object, and this will add the data to the current buffer (buffer), or issue a read call on the IO::Socket object and read "max_message_size" bytes of data.

If the resulting buffer exceeds "max_message_size", this will return undef and sets an error object, so you need to check that the size of the current buffer + the data you provide doe snot exceed the value of "max_message_size"

_extract_number

Provided with some value and this will extract any digit, count the number of spaces and return an integer of the number extracted divided by the number of spaces found.

This is called by the methods "number1" and "number2"

CONSTANTS

The following constants are available and can be exported into your name space either individually, or by using the tag :all

PARSE_DONE

Returned by "parse_chunk" when the parsing is done.

PARSE_INCOMPLETE

Returned by "parse_chunk" when the parsing is incomplete.

PARSE_WAITING

Returned by "parse_chunk" when the parsing is ongoing and the double line end of header separator has not yet been reached.

PARSE_MAYBE_MORE

Returned by "parse_chunk" to indicate that maybe more data is expected.

CREDITS

Credits to David Robins for code borrowed from HTTP::Parser for chunk parsing

AUTHOR

Jacques Deguest <jack@deguest.jp>

SEE ALSO

perl

COPYRIGHT & LICENSE

Copyright(c) 2021 DEGUEST Pte. Ltd. DEGUEST Pte. Ltd.