The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

HTTP::Server::Encrypt - HTTP server with encrypt BODY section

SYNOPSIS

        use HTTP::Server::Encrypt qw(http_server_start);

        my %http_conf;
        $http_conf{'port'} = 80;
        $http_conf{'username'} = 'username';
        $http_conf{'passwd'} = 'passwd';
        $http_conf{'min_spare'} = 2;
        $http_conf{'max_spare'} = 6;
        $http_conf{'static_expires_secs'} = 7200;
        $http_conf{'docroot'} = 'plugins/';
        $http_conf{'blowfish_key'} = $key;
        $http_conf{'blowfish_encrypt'} = 'yes';
        $http_conf{'blowfish_decrypt'} = 'yes';
        $http_conf{'ip_allow'} = \%ip_allow;
        $http_conf{'ip_deny'} = \%ip_deny;
    $http_conf{'log_dir'} = '/var/log/httpd_encrype/';

        http_server_start(\%http_conf);

DESCRIPTION

A pure Perl WebServer with additional features below.

  • Counld encrypt response BODY section or decrypt resquest BODY section with BlowFish CBC.

  • Support HTTP Basic Authentication.

  • Minimum and maximum number of prefork processes is configurable.

  • Cache static request`s response in memory.

  • Route dynamic requests to file.

  • Built-in IP filter.

  • Support protocol PON (Perl Object Notation).

USAGE

Usage of HTTP::Server::Encrypt is very simple.

http_server_start(%params)

To set up a new HTTP Server, call the http_server_start method. You Get All Done. It will run as a daemon.

If your want do things after http_server_start method, you may use this:

    my $parent = fork();
    unless($parent)
    {
        http_server_start(\%http_conf);
        exit 1;
    }

    my $pidfile = __FILE__ . ".pid";
    for(1..9)
    {
        last if -s $pidfile;
        sleep 1;
    }

    ... #server already up. do your things ...

http_server_start accepts the following named parameters in %params:

  • port

    The port of the daemon to which you wish to listen on. Defaults to 80.

  • protocol

    Value http for protocol HTTP. Value pon for protocol PON.

  • min_spare

    How many child will be forked when the server start.

  • max_spare

    Maximum number of processes can be forked.

  • docroot

    This directive sets the directory from which the server will serve files. Request GET /script.pl will be responsed by /var/www/html/script.pl if you this set to /var/www/html/.

  • cache_expires_secs

    Set the HTTP "Cache-Control: max-age" value for static content.

  • username

    Set the HTTP Basic Authentication username.

  • passwd

    Set the HTTP Basic Authentication password. if username and password are not be set, HTTP Basic Authentication disabled.

  • blowfish_key

    Set the BODY encrpyt key. if not set, BODY encrypt disabled.

  • blowfish_encrypt

    Set enable encrpy the send response BODY section.

  • blowfish_decrypt

    Set enable encrpy the recieved request BODY section.

  • ip_allow

    Set ip list allow acccess.

  • ip_deny

    Set ip list deny access.

  • log_dir

    Set log directory. Disable log if value eq no.

PERFORMANCE

The Module has about more the half of request/sec performance compared to apache 2.2.I got 3000 req/sec on Xeon 5520/8G which httpd got 6000. Your can trade off between req/sec and sec/req yourself using the config min_spare and max_spare.

ABOUT PON

That is a very simple and friendly Network Protocol for PERL. I use it on my distributed system communication.Because it works just like JSON, I called it "PON".

AUTHOR

Written by ChenGang, yikuyiku.com@gmail.com

http://blog.yikuyiku.com/

COPYRIGHT

Copyright (c) 2011 ChenGang. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

HTTP::Daemon, HTTP::Server::Simple