Simple

NAME HTTP::Server::Simple - small embedded HTTP server

SYNOPSIS

use HTTP::Server::Simple;
    HTTP::Server::Simple $server.new;
    $server.run;   # says "alive" on port 8080

Normally one would use a class that wraps this server with a familiar web API, such as CGI, FastCGI or PSGI. HTTP::Server::Simple is a role that classes can import with a 'does'. For example:

class HTTP::Server::Simple::Example does HTTP::Server::Simple;

DESCRIPTION This is a Perl 6 re-implementation of the Perl 5 HTTP::Server::Simple. Web applications generally do use this directly, but use a subclass such as HTTP::Server::Simple::CGI, or similar ones based on FastCGI or PSGI.

ATTRIBUTES

host The server's IP address (rw)

port The port server is to run on (ro)

METHODS

new Construct and return a server object. The optional argument is a port number (default 8080). The server begins to listen and accept incoming connections on the port when the run method is executed.

run Start the server as foreground process in an infinite loop. The server is either a Net::Server, a subclass of that, or (default) a minimal emulation of it.

background Fork and run the child process as a server daemon. Not Yet Implemented.

handler Called from process_request. Sends a default response to the client.

setup Called with named parameters: method, protocol, request_uri, path, query_string, port, peername, peeraddr, localname. As in the Perl 5 version, the default setup handler takes each tries to call

headers

process_request Called from _default_run. Calls getpeername, valid_http_method, setup, parse_headers, headers, post_setup_hook, handler.

parse_request

parse_headers

setup_listener Prepares the server TCP socket up to the bind and listen operations. Called from run.

after_setup_listener Called by run as an event hook, the default handler does nothing.

TODO Refactor and re-structure if necessary to be more compatible with the Perl 5 version. This requires testing with webserver applications that have been ported.

SEE ALSO Most of the code was inspired by the following Perl 5 modules: HTTP::Server::Simple Net::Server HTTP::Daemon

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.