Mira::Server::Static - Serve static files with HTTP::Server::Simple
package MyServer; use base qw(HTTP::Server::Simple::CGI); use Mira::Server::Static; my $webroot = '/var/www'; sub handle_request { my ( $self, $cgi ) = @_; if ( !$self->serve_static( $cgi, $webroot ) ) { print "HTTP/1.0 404 Not found\r\n"; print $cgi->header, $cgi->start_html('Not found'), $cgi->h1('Not found'), $cgi->end_html; } } package main; my $server = MyServer->new(); $server->run();
this mixin adds a method to serve static files from your HTTP::Server::Simple subclass.
this module is a copy from HTTP::Server::Simple::Static, with this changes:
replace File::LibMagic by LWP::MediaTypes
add index.html to paths is not equal: m{/$} or m{\..*?$}
Takes a reference to the CGI object and a document root path, and tries to serve a static file. Returns 0 if the file does not exist, returns 1 on success.
This method sets the Date and Last-Modified HTTP headers when sending a response for a valid file. Further to this, the method supports clients which send an If-Modified-Since HTTP header in the request, it will return a 304 Not Modified response if the file is unchanged. See RFC-2616 for full details.
Date
Last-Modified
If-Modified-Since
Not Modified
If the client makes a HEAD request then no message body will be returned in the response.
HEAD
Bugs or wishlist requests should be submitted via http://rt.cpan.org/
The LWP::MediaTypes module is used to detect the MIME-type of a file. The URI::Escape module is used for URI handling. The HTTP::Date module is used to format the timestamp in the Last-Modified HTTP header.
HTTP::Server::Simple, HTTP::Server::Simple::CGI, HTTP::Server::Simple::Static
kiamazi kiavash@cpan.org
kiavash@cpan.org
Copyright 2017. kiamazi kiavash@cpan.org
You may distribute this code under the same terms as Perl itself.
To install Mira, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mira
CPAN shell
perl -MCPAN -e shell install Mira
For more information on module installation, please visit the detailed CPAN module installation guide.