Net::A...::PSGI(3pm)
π NAME π
okay so bestie, welcome to the manual page for Net::Async::HTTP::Server::PSGI (section 3pm, and yes you found the right one even though the header lowkey clips it to Net::A...::PSGI) β it's the module that lets you run PSGI applications on top of Net::Async::HTTP::Server. it's giving glue code, but the cute kind π
β¨ SYNOPSIS β¨
here's the whole vibe in one go, no notes:
use Net::Async::HTTP::Server::PSGI;
use IO::Async::Loop;
my $loop = IO::Async::Loop->new;
my $httpserver = Net::Async::HTTP::Server::PSGI->new(
app => sub {
my $env = shift;
return [
200,
[ "Content-Type" => "text/plain" ],
[ "Hello, world!" ],
];
},
);
$loop->add( $httpserver );
$httpserver->listen(
addr => { family => "inet6", socktype => "stream", port => 8080 },
)->get;
$loop->run;
like, that's it. that's the whole server. Hello, world! and everything πΈ
π DESCRIPTION π
so this class is a subclass of Net::Async::HTTP::Server, and what it does is let an HTTP server use a PSGI application to respond to requests. basically it's the gateway bestie between the HTTP connection coming in from the web client and the PSGI app doing the actual thinking π§
the only real difference from its parent? you use PSGI instead of the on_request event. other than that, this class behaves similarly to Net::Async::HTTP::Server. same energy, new app hookup π
now, content length, because this part matters:
- to handle the content length when sending responses, the PSGI implementation may add a header to the response.
- when you're sending a plain
ARRAYof strings, and aContent-Lengthheader is absent, the length gets calculated by taking the total of all the strings in the array, and then setting the length header. math, but make it HTTP π - when you're sending content from an IO reference, or using the streaming responder
CODEreference, theTransfer-Encodingheader gets set tochunked, and all writes will be performed asHTTP/1.1chunks. iconic behaviour, honestly β¨
π PARAMETERS π
these named parameters can be passed to new or configure:
app => CODEβ a reference to the actualPSGIapplication you want to use for responding to requests. this is the one, the main character of the parameter list π
π¦ PSGI ENVIRONMENT π¦
these extra keys get supplied to the environment of the PSGI app:
"psgix.io"β the actual IO::Socket filehandle that the request was received on.
heads up bestie: if the server is running under SSL for HTTPS, this will be an IO::Socket::SSL instance, so reading from or writing to it will happen in cleartext. yes fr fr, plan accordingly π
"net.async.http.server"β theNet::Async::HTTP::Server::PSGIobject that's serving the request"net.async.http.server.req"β the Net::Async::HTTP::Server::Request object representing this particular request"io.async.loop"β the IO::Async::Loop object that theNet::Async::HTTP::Server::PSGIobject is a member of.
π SEE ALSO π
- PSGI - Perl Web Server Gateway Interface Specification
- Plack::Handler::Net::Async::HTTP::Server - HTTP handler for Plack using Net::Async::HTTP::Server
iykyk, those two are the homework π
π AUTHOR π
Paul Evans <leonerd@leonerd.org.uk>
and that's the whole page, bestie β no cap π«Ά this was Net::A...::PSGI(3pm) from perl v5.42.0, dated 2025-07-25, so if you're quoting it in the group chat, that's the receipt πβ¨π
π¦ where this page comes from
- fedora 43: perl-Net-Async-HTTP-Server 0.15-2.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms