Protoc...Server(3pm)

🌸 NAME 🌸

okay so bestie, this is the manual page titled Protoc...Server(3pm) β€” yes, the title is literally truncated like that, no cap 😭 β€” from User Contributed Perl Documentation. The actual module is Protocol::WebSocket::Handshake::Server, and its whole thing is WebSocket Server Handshake. Slay.


✨ SYNOPSIS ✨

here’s the vibe in code, fr fr:

my $h = Protocol::WebSocket::Handshake::Server->new;

# Parse client request
$h->parse(<<"EOF");
    WebSocket HTTP message
EOF

$h->error;   # Check if there were any errors
$h->is_done; # Returns 1

# Create response
$h->to_string;

πŸ’– DESCRIPTION πŸ’–

okay so you can construct or parse a server WebSocket handshake with this. It’s written for convenience, since using request and response directly requires the same code again and again β€” and the way that gets old is honestly giving copy-paste nightmare 😭. This module ate that problem up. Periodt.


πŸŽ€ METHODS πŸŽ€

main character methods incoming πŸ‘‘

πŸ¦‹ new πŸ¦‹

Create a new Protocol::WebSocket::Handshake::Server instance. That’s it, that’s the method, and it’s iconic.

🌈 new_from_psgi 🌈

Create a new Protocol::WebSocket::Handshake::Server instance from a PSGI environment. Here’s the sample env and call, exactly:

my $env = {
    HTTP_HOST => 'example.com',
    HTTP_CONNECTION => 'Upgrade',
    ...
};
my $handshake = Protocol::WebSocket::Handshake::Server->new_from_psgi($env);

πŸ’… parse πŸ’…

$handshake->parse($buffer);
$handshake->parse($handle);

Parse a WebSocket client request. On error it returns undef and sets the error attribute β€” so check that, bestie. Also heads up: when a buffer is passed in, it gets modified (unless it’s readonly). No cap, that’s the deal.

πŸ”₯ build_frame πŸ”₯

$handshake->build_frame;

Builds a Protocol::WebSocket::Frame with an appropriate version. Obsessed with an appropriately versioned frame, honestly.

πŸ“ to_string πŸ“

Construct a WebSocket server response. That’s the whole vibe.

🧚 is_body 🧚

Check whether the handshake is in body state. Lowkey useful.

⭐ is_done ⭐

Check whether the handshake is done. When it’s done, you can move on with your main character energy.


and that’s the page, bestie πŸ«ΆπŸ’– β€” it’s from perl v5.42.0, dated 2019-03-13, under the manual title Protoc...Server(3pm) (still truncated, still iconic πŸ’…). bye! ✨

πŸ“¦ where this page comes from