Serve arbitrary files from the www directory (FHEMWEB)

git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@2684 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig
2013-02-10 19:22:55 +00:00
parent 05393b5f0d
commit 3be8c88c08
3 changed files with 30 additions and 13 deletions

View File

@@ -8,30 +8,32 @@ use IO::Socket::INET;
use MIME::Base64;
my %ext2MIMEType= qw{
txt text/plain
html text/html
pdf application/pdf
css text/css
jpg image/jpeg
png image/png
gif image/gif
html text/html
ico image/x-icon
};
jpg image/jpeg
js text/javascript
pdf application/pdf
png image/png
svg image/svg+xml
txt text/plain
my $KNOWNEXTENSIONS= 'txt|html|pdf|css|jpg|png|gif|ico';
};
sub
ext2MIMEType($) {
my ($ext)= @_;
my $MIMEType= $ext ? $ext2MIMEType{$ext} : "";
return $MIMEType ? $MIMEType : "";
return "text/plain" if(!$ext);
my $MIMEType = $ext2MIMEType{lc($ext)};
return ($MIMEType ? $MIMEType : "text/$ext");
}
sub
filename2MIMEType($) {
my ($filename)= @_;
$filename =~ m/^(.*)\.($KNOWNEXTENSIONS)$/;
return ext2MIMEType($2);
$filename =~ m/^.*\.([^\.]*)$/;
return ext2MIMEType($1);
}