AnyEve...Request(3pm)

πŸ“¦
version 0.04 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– AnyEve...Request(3pm) β€” User Contributed Perl Documentation πŸ’–

okay bestie, welcome to the manual page for AnyEvent::FCGI::Request β€” she's the single FastCGI request handle for AnyEvent::FCGI, and she's iconic, no cap. this is your group chat crash course, let's go 🫢


✨ NAME ✨

AnyEvent::FCGI::Request β€” a single FastCGI request handle for AnyEvent::FCGI


🌸 SYNOPSIS 🌸

use AnyEvent;
use AnyEvent::FCGI;
use CGI::Stateless;

my $fcgi = new AnyEvent::FCGI(
    port => 9000,
    on_request => sub {
        my $request = shift;

        local *STDIN; open STDIN, '<', \$request->read_stdin;
        local %ENV = %{$request->params};
        local $CGI::Q = new CGI::Stateless;

        $request->respond(
            'Hello, ' . (CGI::param('name') || 'anonymous'),
            'Content-Type' => 'text/html; charset=utf8',
            'Set-Cookie' => 'cookie_a=1; path=/',
            'Set-Cookie' => 'cookie_b=2; path=/',
        );
    }
);

AnyEvent->loop;

like, that's the whole vibe right there ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

so this is the request object that AnyEvent::FCGI generates for you. the way that works is: when it gets handed to your controlling program, every request already has its parameters and its STDIN data all ready to go. your program can then write response data to the STDOUT stream, write messages to the STDERR stream, and eventually finish the request off. it's giving very organized, very main character 😌

lowkey important though: your program would not use this module directly if it's using AnyEvent::FCGI. instead, objects of this class get passed into the on_request callback of the containing AnyEvent::FCGI object. iykyk πŸ’…


πŸ’… METHODS πŸ’…

is_active

returns false if the webserver has already closed the control connection. if that's happened, no further work on this request is necessary β€” she's getting discarded, bye πŸ‘‹

you'd use this method if the response is not going to be sent immediately from the on_request callback.

param($key)

this method returns the value of a single request parameter. if no such key exists, you get undef back instead. simple as that bestie πŸ™ˆ

params

this method returns a reference to a hash containing a copy of the request parameters that the webserver sent as part of the request. a copy, okay? not a live link. respect the boundary ✨

read_stdin($size)

this one works similarly to the read(HANDLE) function. it returns the next block of up to $size bytes from the STDIN buffer. if there's no data available any more, then undef is returned instead. snack-sized chunks of input πŸ“

this method appends the given data to the STDOUT stream of the FastCGI request β€” sending it to the webserver so it can be sent to the client. it's the pipeline, babe 🌈

this method appends the given data to the STDERR stream of the FastCGI request, sending it to the webserver. that's the other stream, for the stuff that isn't the response. keep them separate πŸ’œ

finish

when the request has been dealt with, this method should be called, because it indicates to the webserver that it is finished. periodt πŸ™Œ

⚠️ after calling this method, no more data may be appended to the STDOUT stream. like, at all. she's closed. don't try it.

respond($content, @headers)

this method sends the response to the webserver and finishes the request β€” a two-for-one, obsessed πŸ˜­πŸ’–

the HTTP reply code can be specified in the Status header (200 by default, naturally).

this method can be used instead of print_stdout and finish, so it's the shortcut girlies will reach for ⌚✨


and that's the whole page, bestie πŸŽ€

source/version: perl v5.36.0 Β· date: 2022-10-14

mwah, go write some slay FastCGI handlers, you've got this πŸ‘‘πŸ’…πŸ¦‹

πŸ“¦ where this page comes from