ETags by Matthias
git-svn-id: https://svn.fhem.de/fhem/trunk@2150 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
@@ -16,7 +16,8 @@
|
|||||||
- bugfix: FHEMWEB slider with min > 0
|
- bugfix: FHEMWEB slider with min > 0
|
||||||
- change: FHEMWEB CORS moved to options
|
- change: FHEMWEB CORS moved to options
|
||||||
- change: FHEMWEB closing old TCP connections
|
- 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)
|
- 2012-10-28 (5.3)
|
||||||
- feature: added functions trim, ltrim, rtrim, UntoggleDirect,
|
- feature: added functions trim, ltrim, rtrim, UntoggleDirect,
|
||||||
|
|||||||
@@ -1236,18 +1236,36 @@ sub
|
|||||||
FW_returnFileAsStream($$$$$)
|
FW_returnFileAsStream($$$$$)
|
||||||
{
|
{
|
||||||
my ($path, $suffix, $type, $doEsc, $cacheable) = @_;
|
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)) {
|
if(!open(FH, $path)) {
|
||||||
FW_pO "<div id=\"content\">$path: $!</div>";
|
FW_pO "<div id=\"content\">$path: $!</div>";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
binmode(FH) if($type !~ m/text/); # necessary for Windows
|
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 $expires = $cacheable ? ("Expires: ".localtime(time()+900)." GMT\r\n"): "";
|
||||||
my $compr = ((int(@FW_enc) == 1 && $FW_enc[0] =~ m/gzip/) && $FW_use_zlib) ?
|
my $compr = ((int(@FW_enc) == 1 && $FW_enc[0] =~ m/gzip/) && $FW_use_zlib) ?
|
||||||
"Content-Encoding: gzip\r\n" : "";
|
"Content-Encoding: gzip\r\n" : "";
|
||||||
print $c "HTTP/1.1 200 OK\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",
|
"Transfer-Encoding: chunked\r\n",
|
||||||
"Content-Type: $type; charset=$FW_encoding\r\n\r\n";
|
"Content-Type: $type; charset=$FW_encoding\r\n\r\n";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user