Net::Async::HTTP::Server::PSGI - use PSGI applications with Net::Async::HTTP::Server
Net::Async::HTTP::Server::PSGI
PSGI
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 [ 200, [ "Content-Type" => "text/plain" ], [ "Hello, world!" ], ]; }, ); $loop->add( $httpserver ); $httpserver->listen( addr => { family => "inet6", socktype => "stream", port => 8080 }, )->get; $loop->run;
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.
on_request
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.
ARRAY
Content-Length
CODE
Transfer-Encoding
chunked
HTTP/1.1
The following named parameters may be passed to new or configure:
new
configure
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:
psgix.io
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.
net.async.http.server
The Net::Async::HTTP::Server::PSGI object 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.
PSGI - Perl Web Server Gateway Interface Specification
Plack::Handler::Net::Async::HTTP::Server - HTTP handler for Plack using Net::Async::HTTP::Server
Paul Evans <leonerd@leonerd.org.uk>
To install Net::Async::HTTP::Server, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::Async::HTTP::Server
CPAN shell
perl -MCPAN -e shell install Net::Async::HTTP::Server
For more information on module installation, please visit the detailed CPAN module installation guide.