Protoc...equest(3pm)
π NAME π
Protocol::WebSocket::Request β WebSocket Request, bestie. This page is repping the User Contributed Perl Documentation, and it's here to explain the request side of WebSocket life without making your brain do a lil error noise. π«Ά
β¨ SYNOPSIS β¨
okay so first up, constructor energy:
# Constructor
my $req = Protocol::WebSocket::Request->new(
host => 'example.com',
resource_name => '/demo'
);
$req->to_string; # GET /demo HTTP/1.1
# Upgrade: WebSocket
# Connection: Upgrade
# Host: example.com
# Origin: http://example.com
# Sec-WebSocket-Key1: 32 0 3lD& 24+< i u4 8! -6/4
# Sec-WebSocket-Key2: 2q 4 2 54 09064
#
# x#####
and now the parser era:
# Parser
my $req = Protocol::WebSocket::Request->new;
$req->parse("GET /demo HTTP/1.1\x0d\x0a");
$req->parse("Upgrade: WebSocket\x0d\x0a");
$req->parse("Connection: Upgrade\x0d\x0a");
$req->parse("Host: example.com\x0d\x0a");
$req->parse("Origin: http://example.com\x0d\x0a");
$req->parse(
"Sec-WebSocket-Key1: 18x 6]8vM;54 *(5: { U1]8 z [ 8\x0d\x0a");
$req->parse(
"Sec-WebSocket-Key2: 1_ tx7X d < nw 334J702) 7]o}` 0\x0d\x0a");
$req->parse("\x0d\x0aTm[K T2u");
πΈ DESCRIPTION πΈ
Construct or parse a WebSocket request. That's the whole description, and honestly it ate. π
π ATTRIBUTES π
the attribute lineup is:
hostkey1key2number1number2originresource_name
that's the full guest list from the page β no extra attributes hiding in the group chat. π¦
π METHODS π
π new π
Create a new Protocol::WebSocket::Request instance. Fresh out the box. β¨
π new_from_psgi π
Create a new Protocol::WebSocket::Request instance from a PSGI environment. Here's the shape:
my $env = {
HTTP_HOST => 'example.com',
HTTP_CONNECTION => 'Upgrade',
...
};
my $req = Protocol::WebSocket::Request->new_from_psgi($env);
π parse π
Parse a WebSocket request. You can feed it a buffer or a handle:
$req->parse($buffer);
$req->parse($handle);
Heads up: the incoming buffer is modified. That's not a drill, bestie β the page says it right there. π
π to_string π
Construct a WebSocket request. It's giving builder energy. π₯
π connection π
$self->connection;
A shortcut for "$self-"field('Connection')>.
π cookies π
cookies is on the method list. The page doesn't give it a description, so I'm not gonna invent one. Respect the mystery. π
π upgrade π
$self->upgrade;
A shortcut for "$self-"field('Upgrade')>.
k bye bestie β this iconic little page signs off as Protoc...equest(3pm), sourced from perl v5.42.0, dated 2019-03-13. π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Protocol-WebSocket 0.26-bp160.1.11 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms