75 lines
1015 B
Perl
75 lines
1015 B
Perl
#
|
|
# SMArT
|
|
#
|
|
# Static file server
|
|
#
|
|
# Copyright 2001 Wilmer van der Gaast (lintux@lintux.cx)
|
|
#
|
|
# Updated with favicon and modern asset MIME type support.
|
|
#
|
|
|
|
sub handle_request()
|
|
{
|
|
$f = $c[1];
|
|
$f =~ s/[^-_\.A-Za-z0-9]//g;
|
|
if( ! open( FILE, $smart_static_dir . '/' . $f ) )
|
|
{
|
|
error( 404 );
|
|
}
|
|
$e = $f;
|
|
$e =~ s/^.*\.//;
|
|
$e = lc( $e );
|
|
if( $e eq 'html' )
|
|
{
|
|
$t = 'text/html';
|
|
}
|
|
elsif( $e eq 'gif' )
|
|
{
|
|
$t = 'image/gif';
|
|
}
|
|
elsif( $e eq 'jpg' || $e eq 'jpeg' )
|
|
{
|
|
$t = 'image/jpeg';
|
|
}
|
|
elsif( $e eq 'png' )
|
|
{
|
|
$t = 'image/png';
|
|
}
|
|
elsif( $e eq 'ico' )
|
|
{
|
|
$t = 'image/x-icon';
|
|
}
|
|
elsif( $e eq 'svg' )
|
|
{
|
|
$t = 'image/svg+xml';
|
|
}
|
|
elsif( $e eq 'webp' )
|
|
{
|
|
$t = 'image/webp';
|
|
}
|
|
elsif( $e eq 'css' )
|
|
{
|
|
$t = 'text/css';
|
|
}
|
|
elsif( $e eq 'js' )
|
|
{
|
|
$t = 'application/javascript';
|
|
}
|
|
else
|
|
{
|
|
$t = 'application/octet-stream';
|
|
}
|
|
print <<EOF2;
|
|
HTTP/1.0 200 OK
|
|
Content-Type: $t
|
|
$server_id
|
|
|
|
EOF2
|
|
binmode( FILE );
|
|
while( read( FILE, $buf, 8192 ) )
|
|
{
|
|
print $buf;
|
|
}
|
|
close( FILE );
|
|
}
|