HTTP::...Static(3pm)

πŸ“¦
version 0.14 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ NAME ✨

HTTP::Server::Simple::Static β€” serve static files with HTTP::Server::Simple πŸ’…

(also known as HTTP::...Static(3pm), from the User Contributed Perl Documentation corner of the manpage universe 🫢)


🌸 VERSION 🌸

This documentation refers to HTTP::Server::Simple::Static version 0.13. that's the vibe check, bestie, that's the number πŸ’–


πŸ¦‹ SYNOPSIS πŸ¦‹

okay so picture this: you've got a server subclass, and you want it to serve files off disk. here's the whole ritual ✨

package MyServer;

use base qw(HTTP::Server::Simple::CGI);
use HTTP::Server::Simple::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();

like. it just runs. main character energy fr fr πŸ‘‘


πŸ’– DESCRIPTION πŸ’–

this mixin adds a method to serve static files from your HTTP::Server::Simple subclass. that's it, that's the whole plot, and honestly? it ate. πŸ“


πŸŽ€ SUBROUTINES/METHODS πŸŽ€

serve_static( $cgi, $base )

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. and not only that, bestie β€” further to this, the method supports clients which send an If-Modified-Since HTTP header in the request. if the file is unchanged, it will return a 304 "Not Modified" response. See RFC-2616 for full details, iykyk πŸ“š

If the client makes a HEAD request, then no message body will be returned in the response. just headers, no crumbs. πŸ’€


πŸ™ˆ BUGS AND LIMITATIONS πŸ™ˆ

Bugs or wishlist requests should be submitted via http://rt.cpan.org/

not me telling you to file a bug report but like... do it. it's giving responsible. 🫢

🧚 DEPENDENCIES 🧚

  • The File::LibMagic 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 πŸ•°οΈ

🌈 SEE ALSO 🌈

  • HTTP::Server::Simple
  • HTTP::Server::Simple::CGI

go read those next bestie, they're literally the prequels πŸ’œ


πŸ‘‘ AUTHOR πŸ‘‘

Stephen Quinney sjq-perl@jadevine.org.uk

Thanks to Marcus Ramberg marcus@thefeed.no and Simon Cozens for initial implementation. shoutout to the OGs, no cap 🫑


Copyright 2006 - 2017. Stephen Quinney sjq-perl@jadevine.org.uk

You may distribute this code under the same terms as Perl itself.


okay and that's a wrap on our little journey πŸŽ€ this was perl v5.34.0, dated 2022-06-14, and the page itself goes by HTTP::...Static(3pm). periodt. go serve some static files, you icon πŸ’…βœ¨

πŸ“¦ where this page comes from