mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 12:49:34 +00:00
- new helper functions ext2MIMEType(), filename2MIMEType()
- 02_HTTPSRV also serves files from subdirectories - 02_HTTPSRV sends MIME types git-svn-id: https://svn.fhem.de/fhem/trunk@1825 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
e3efc49912
commit
9ad884b8d4
@ -11,7 +11,7 @@ package main;
|
||||
use strict;
|
||||
use warnings;
|
||||
use vars qw(%data);
|
||||
|
||||
use HttpUtils;
|
||||
|
||||
#########################
|
||||
sub
|
||||
@ -71,11 +71,13 @@ HTTPSRV_CGI(){
|
||||
if($request !~ m,^/.+/.*,) {
|
||||
$request= "$request/index.html";
|
||||
}
|
||||
if($request =~ m,^\/(.*)/(.*)$,) {
|
||||
if($request =~ m,^/([^/]+)/(.*)$,) {
|
||||
my $name= $1;
|
||||
my $filename= $2;
|
||||
my $MIMEtype= filename2MIMEType($filename);
|
||||
#return("text/plain; charset=utf-8", "HTTPSRV device: $name, filename: $filename, MIME type: $MIMEtype");
|
||||
if(!defined($defs{$name})) {
|
||||
return("text/plain; charset=utf-8", "Unknown HTTPSRV device: $name");
|
||||
return("$MIMEtype; charset=utf-8", "Unknown HTTPSRV device: $name");
|
||||
}
|
||||
my $directory= $defs{$name}{fhem}{directory};
|
||||
$filename= "$directory/$filename";
|
||||
|
@ -6,6 +6,34 @@ use strict;
|
||||
use warnings;
|
||||
use IO::Socket::INET;
|
||||
|
||||
my %ext2MIMEType= qw{
|
||||
txt text/plain
|
||||
html text/html
|
||||
pdf application/pdf
|
||||
css text/css
|
||||
jpg image/jpeg
|
||||
png image/png
|
||||
gif image/gif
|
||||
ico image/x-icon
|
||||
};
|
||||
|
||||
my $KNOWNEXTENSIONS= 'txt|html|pdf|css|jpg|png|gif|ico';
|
||||
|
||||
sub
|
||||
ext2MIMEType($) {
|
||||
my ($ext)= @_;
|
||||
my $MIMEType= $ext ? $ext2MIMEType{$ext} : "";
|
||||
return $MIMEType ? $MIMEType : "";
|
||||
}
|
||||
|
||||
sub
|
||||
filename2MIMEType($) {
|
||||
my ($filename)= @_;
|
||||
$filename =~ m/^(.*)\.($KNOWNEXTENSIONS)$/;
|
||||
return ext2MIMEType($2);
|
||||
}
|
||||
|
||||
|
||||
##################
|
||||
sub
|
||||
urlEncode($) {
|
||||
|
@ -313,14 +313,7 @@ FW_ServeSpecial($$$) {
|
||||
binmode(FH) if($ext =~ m/$ICONEXTENSION/); # necessary for Windows
|
||||
FW_pO join("", <FH>);
|
||||
close(FH);
|
||||
$FW_RETTYPE = "text/plain" if($ext eq "txt");
|
||||
$FW_RETTYPE = "text/html" if($ext eq "html");
|
||||
$FW_RETTYPE = "application/pdf" if($ext eq "pdf");
|
||||
$FW_RETTYPE = "text/css" if($ext eq "css");
|
||||
$FW_RETTYPE = "image/jpeg" if($ext eq "jpg");
|
||||
$FW_RETTYPE = "image/png" if($ext eq "png");
|
||||
$FW_RETTYPE = "image/gif" if($ext eq "gif");
|
||||
$FW_RETTYPE = "image/x-icon" if($ext eq "ico");
|
||||
$FW_RETTYPE = ext2MIMEType($ext);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user