NAME

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

SYNOPSIS

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 },
   on_listen_error => sub { die "Cannot listen - $_[-1]\n" },
);

$loop->run;

DESCRIPTION

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.

PARAMETERS

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

PSGI ENVIRONMENT

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

net.async.http.server

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

net.async.http.server.req

The Net::Async::HTTP::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

AUTHOR

Paul Evans <leonerd@leonerd.org.uk>