Net::A...::PSGI(3pm)

πŸ“¦
version 0.15 Β· 3 versions
, in fedora 43

πŸ’– 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 ARRAY of strings, and a Content-Length header 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 CODE reference, the Transfer-Encoding header gets set to chunked, and all writes will be performed as HTTP/1.1 chunks. iconic behaviour, honestly ✨

πŸŽ€ PARAMETERS πŸŽ€

these named parameters can be passed to new or configure:

  • app => CODE β€” a reference to the actual PSGI application 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" β€” the Net::Async::HTTP::Server::PSGI object 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 the Net::Async::HTTP::Server::PSGI object 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