NAME

Net::Server::HTTP - very basic Net::Server based HTTP server class

TEST ONE LINER

perl -e 'use base qw(Net::Server::HTTP); main->run(port => 8080)'

SYNOPSIS

use base qw(Net::Server::HTTP);
__PACKAGE__->run;

sub process_http_request {
    my $self = shift;

    print "Content-type: text/html\n\n";
    print "<form method=post action=/bam><input type=text name=foo><input type=submit></form>\n";

    require Data::Dumper;
    local $Data::Dumper::Sortkeys = 1;

    require CGI;
    my $form = {};
    my $q = CGI->new; $form->{$_} = $q->param($_) for $q->param;

    print "<pre>".Data::Dumper->Dump([\%ENV, $form], ['*ENV', 'form'])."</pre>";
}

DESCRIPTION

Even though Net::Server::HTTP doesn't fall into the normal parallel of the other Net::Server flavors, handling HTTP requests is an often requested feature and is a standard and simple protocol.

Net::Server::HTTP begins with base type MultiType defaulting to Net::Server::Fork. It is easy to change it to any of the other Net::Server flavors by passing server_type => $other_flavor in the server configurtation. The port has also been defaulted to port 80 - but could easily be changed to another through the server configuration. You can also very easily add ssl by including, proto=>"ssl" and provide a SSL_cert_file and SSL_key_file.

METHODS

process_http_request

Will be passed the client handle, and will have STDOUT and STDIN tied to the client.

During this method, the %ENV will have been set to a standard CGI style environment. You will need to be sure to print the Content-type header. This is one change from the other standard Net::Server base classes.

During this method you can read from %ENV and STDIN just like a normal HTTP request in other web servers. You can print to STDOUT and Net::Server will handle the header negotiation for you.

Note: Net::Server::HTTP has no concept of document root or script aliases or default handling of static content. That is up to the consumer of Net::Server::HTTP to work out.

Net::Server::HTTP comes with a basic %ENV display installed as the default process_http_request method.

process_request

This method has been overridden in Net::Server::HTTP - you should not use it while using Net::Server::HTTP. This overridden method parses the environment and sets up request alarms and handles dying failures. It calls process_http_request once the request is ready and headers have been parsed.

send_status

Takes an HTTP status and a message. Sends out the correct headers.

send_501

Calls send_status with 501 and the argument passed to send_501.

OPTIONS

In addition to the command line arguments of the Net::Server base classes you can also set the following options.

max_header_size

Defaults to 100_000. Maximum number of bytes to read while parsing headers.

server_revision

Defaults to Net::Server::HTTP/$Net::Server::VERSION.

timeout_header

Defaults to 15 - number of seconds to wait for parsing headers.

timeout_idle

Defaults to 60 - number of seconds a request can be idle before the request is closed.

TODO

Add support for writing out HTTP/1.1.

AUTHOR

Paul T. Seamons paul@seamons.com

THANKS

See Net::Server

SEE ALSO

Please see also Net::Server::Fork, Net::Server::INET, Net::Server::PreFork, Net::Server::PreForkSimple, Net::Server::MultiType, Net::Server::Single Net::Server::SIG Net::Server::Daemonize Net::Server::Proto