2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 18:59:33 +00:00

ETags by Matthias

git-svn-id: https://svn.fhem.de/fhem/trunk@2150 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2012-11-21 19:47:19 +00:00
parent e6010cde18
commit 0b966a5c70
2 changed files with 22 additions and 3 deletions

View File

@ -16,7 +16,8 @@
- bugfix: FHEMWEB slider with min > 0
- change: FHEMWEB CORS moved to options
- change: FHEMWEB closing old TCP connections
- change: FHEMWEB added "Associated with" to detail-screen
- change: FHEMWEB added "Associated with" to detail-screen (Uli)
- change: FHEMWEB added ETag headers (Matthias)
- 2012-10-28 (5.3)
- feature: added functions trim, ltrim, rtrim, UntoggleDirect,

View File

@ -1236,18 +1236,36 @@ sub
FW_returnFileAsStream($$$$$)
{
my ($path, $suffix, $type, $doEsc, $cacheable) = @_;
#Check for If-None-Match header (ETag)
my @if_none_match_lines = grep /If-None-Match/, @FW_httpheader;
my $if_none_match = undef;
if(@if_none_match_lines) {
$if_none_match = $if_none_match_lines[0];
$if_none_match =~ s/If-None-Match: \"(.*)\"/$1/;
}
my $c = $FW_chash->{CD};
my $etag = (stat($path))[9]; #mtime
if(defined($etag) and defined($if_none_match) and $etag eq $if_none_match) {
print $c "HTTP/1.1 304 Not Modified\r\n",
$FW_headercors, "\r\n";
return -1;
}
if(!open(FH, $path)) {
FW_pO "<div id=\"content\">$path: $!</div>";
return 0;
}
binmode(FH) if($type !~ m/text/); # necessary for Windows
my $c = $FW_chash->{CD};
$etag = defined($etag) ? "ETag: \"$etag\"\r\n" : "";
my $expires = $cacheable ? ("Expires: ".localtime(time()+900)." GMT\r\n"): "";
my $compr = ((int(@FW_enc) == 1 && $FW_enc[0] =~ m/gzip/) && $FW_use_zlib) ?
"Content-Encoding: gzip\r\n" : "";
print $c "HTTP/1.1 200 OK\r\n",
$compr, $expires, $FW_headercors,
$compr, $expires, $FW_headercors, $etag,
"Transfer-Encoding: chunked\r\n",
"Content-Type: $type; charset=$FW_encoding\r\n\r\n";