HTTP::Server::Encrypt - HTTP server can encrypt BODY section
use HTTP::Server::Encrypt qw(http_server_start); my %http_conf; $http_conf{'port'} = 80; $http_conf{'docroot'} = "/var/www/htdoc/"; $http_conf{'blowfish_key'} = "somekey"; $http_conf{'blowfish_encrypt'} = 'yes'; $http_conf{'blowfish_decrypt'} = 'yes'; http_server_start(\%http_conf);
A pure Perl WebServer with features below.
Be able to encrypt response BODY section and decrypt resquest BODY section with BlowFish CBC.
HTTP Basic Authentication support.
Prefork processes module.
Use sendfile for station file requests.
Route dynamic requests to file.
Built-in IP filter.
CGI support.
Usage of HTTP::Server::Encrypt is very simple.
To set up a new HTTP Server, just call the http_server_start method. It will run as a daemon.
http_server_start accepts the following named parameters in %params:
port
Default 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
Set the root directory. For example: 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 requesets.
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
Enable encrypt the response BODY.
blowfish_decrypt
Enable encrypt the request BODY.
ip_allow
Allow ip list.
ip_deny
Deny ip list.
log_dir
Set access log directory. Disable log if set to no.
Only PERL script support.
Just scripts in docroot.
For example:
If you docroot set to /var/www/html/.
Request GET /script.pl will be responsed by /var/www/html/script.pl.
There is some vars can be used in the script.
$peer_ip
The IP address from which the user is viewing the current page.
$peer_port
The TCP port from which the user is viewing the current page.
%_GET
HTTP GET variables.
An associative array of variables passed to the current script via the URL parameters.
%_POST
HTTP POST variables.
An associative array of variables passed to the current script via the HTTP POST method.
$_POST
Raw POST data.
%_HEAD
HTTP request headers.
%_ENV
Execution environment information.
An associative array of variables passed to the current script via the environment method.
Above can be used direct.
If you write scripts in Python or C or something not PERL,
You may want use CGI standard, then you can write
use HTTP::Server::Encrypt::CGI;
Instead of
use HTTP::Server::Encrypt;
Then you just put you CGI applications in docroot.
More information in HTTP::Server::Encrypt::CGI.
If your want do things after http_server_start method, you may want 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 ...
Written by ChenGang, yikuyiku.com@gmail.com
http://blog.yikuyiku.com/
Copyright (c) 2011 ChenGang. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
HTTP::Daemon, HTTP::Server::Simple, HTTP::Server::Encrypt::CGI
To install HTTP::Server::Encrypt, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTTP::Server::Encrypt
CPAN shell
perl -MCPAN -e shell install HTTP::Server::Encrypt
For more information on module installation, please visit the detailed CPAN module installation guide.