IO::Lambda::HTTP::Server(3p)

NAME
IO::Lambda::HTTP::Server - simple httpd server

DESCRIPTION
The module exports a single function "http_server" that accepts a callback and a socket, with optional parameters. The callback accepts a "HTTP::Request" object, and is expected to return either a "HTTP::Response" object or a lambda that in turn returns a a "HTTP::Response" object.

SYNOPSIS
   use HTTP::Request;
   use IO::Lambda qw(:all);
   use IO::Lambda::HTTP qw(http_request);
   use IO::Lambda::HTTP::Server;

   my $server = http_server {
        my $req = shift;
        if ( $req->uri =~ /weather/) {
                context( HTTP::Request-> new( GET => "http://www.google.com/?q=weather"));
                return &http_request;
        } else {
                return HTTP::Response->new(200, 'OK', ['Content-Type' => 'text/plain'], "hello world");
        }
   } "localhost:80";
   $server->start; # runs in 'background' now

API

http_server &callback, $socket, [ %options ]
    Creates lambda that listens on $socket, that is either a "IO::Socket::INET" object or a string such as "localhost" or "127.0.0.1:9999".

    The callback accepts a "HTTP::Request" object, and is expected to return either a "HTTP::Response" object or a lambda that in turn returns a a "HTTP::Response" object.

    Options:

    timeout $integer
        Connection timeout or a deadline.

shutdown
    Enter a graceful shutdown mode - stop accepting new connections, handle the running ones, and stop after all connections are served.

SEE ALSO
IO::Lambda, HTTP::Request, HTTP::Response

AUTHOR
Dmitry Karasik, <dmitry@karasik.eu.org>.