NAME
HTTP::Server::EV - Asynchronous HTTP server written in C with request parser.
DESCRIPTION
HTTP::Server::EV - Asynchronous HTTP server using EV event loop. It doesn`t load files received in the POST request in memory as moust of CGI modules does, but stores them directly to tmp files, so it`s useful for handling large files without using a lot of memory.
INCLUDED MODULES
HTTP::Server::EV::CGI - received http request object HTTP::Server::EV::MultipartFile - received file object HTTP::Server::EV::Buffer - non blocking output HTTP::Server::EV::BufTie - workaround for correct handling requests in Coro threads
SYNOPSIS
my $server = HTTP::Server::EV::CGI->new;
$server->listen(90, sub {
my $cgi = shift;
$cgi->attach(*STDOUT);
$cgi->header;
print "Just another Perl server\n";
});
METHODS
new( { options } )
Options:
- tmp_path
-
Directory for saving received files. Tries to create if not found, dies on fail. Default: ./upload_tmpfiles/
- cleanup_on_destroy
-
Usually HTTP::Server::EV::CGI deletes tmp files on DESTROY, but it might by bug if you delete HTTP::Server::EV::CGI object when its files are still opened. Setting on this flag causes HTTP::Server::EV delete all files in tmp_path on program close, but don`t use it if jou have several process working with same tmp dir. Default: 0
- backend
-
Seting on cause HTTP::Server::EV::CGI parse ip from X-Real-IP http header Default: 0
listen( port , sub {callback} )
Binds callback to port. Calls callback and passes HTTP::Server::EV::CGI object in it;
$server->listen( 8080 , sub {
my $cgi = shift;
$cgi->attach(local *STDOUT); # attach STDOUT to socket
$cgi->header; # print http headers to stdout
print "Test page";
});
cleanup
Delete all files in tmp_path. Automatically called on DESTROY if cleanup_on_destroy set
TODO
Write tests
Write request parser error handling - Server drops connection on error(Malformed or too large request), but there is no way to know what error happened.
unbind function
BUGS/WARNINGS
You can`t create two HTTP::Server::EV objects at same process.
Static allocated buffers:
- Can`t listen more than 20 ports at same time
- 4kb for GET/POST form field names
- 4kb for GET values
- 50kb for POST form field values ( not for files. Files are stored into tmp directly from socket stream, so filesize not limited by HTTP::Server::EV)
HTTP::Server::EV drops connection if some buffer overflows. You can change these values in EV.xs and recompile module.
COPYRIGHT AND LICENSE
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.