mberends/http-server-simple/lib/HTTP/Server/Simple

http-server-simple src

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

(head2) host
The server's IP address (rw)
(head2) port
The port server is to run on (ro)

METHODS

(head2) 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.
(head2) 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.
(head2) background
Fork and run the child process as a server daemon. Not Yet Implemented.
(head2) handler
Called from process_request . Sends a default response to the client.
(head2) 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 

 
(head2) headers
(head2) print_banner
Announces on the console that the server is running.
(head2) process_request
Called from _default_run . Calls getpeername , valid_http_method , setup , parse_headers , headers , post_setup_hook , handler .
(head2) parse_request
(head2) parse_headers
(head2) setup_listener
Prepares the server TCP socket up to the bind and listen operations. Called from run .
(head2) 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: L<HTTP::Server::Simple> L<Net::Server> L<HTTP::Daemon>

Perl 6 Tricks and Treats newsletter

Register to the free newsletter now, and get updates and news.
Email:
Name: