Net::Async::HTTP::Server::PSGI - use PSGI applications with Net::Async::HTTP::Server


 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 [
          [ "Content-Type" => "text/plain" ],
          [ "Hello, world!" ],

 $loop->add( $httpserver );

    addr => { family => "inet6", socktype => "stream", port => 8080 },



This subclass of Net::Async::HTTP::Server allows an HTTP server to use a PSGI application to respond to requests. It acts as a gateway between the HTTP connection from the web client, and the PSGI application. Aside from the use of PSGI instead of the on_request event, this class behaves similarly to Net::Async::HTTP::Server.

To handle the content length when sending responses, the PSGI implementation may add a header to the response. When sending a plain ARRAY of strings, if a Content-Length header is absent, the length will be calculated by taking the total of all the strings in the array, and setting the length header. When sending content from an IO reference or using the streaming responder CODE reference, the Transfer-Encoding header will be set to chunked, and all writes will be performed as HTTP/1.1 chunks.


The following named parameters may be passed to new or configure:

app => CODE

Reference to the actual PSGI application to use for responding to requests


The following extra keys are supplied to the environment of the PSGI app:

The actual IO::Socket filehandle that the request was received on.

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.


The Net::Async::HTTP::Server::PSGI object serving the request


The Net::Async::HTTP::Server::Request object representing this particular request


The IO::Async::Loop object that the Net::Async::HTTP::Server::PSGI object is a member of.



Paul Evans <>