mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-07 22:29:19 +00:00
fhem.pl/FHEMWEB: fix HTTPS problem with large streamed files
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@5626 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
7a025240bf
commit
e9c0f8d566
@ -1345,9 +1345,10 @@ FW_fileList($)
|
|||||||
sub
|
sub
|
||||||
FW_outputChunk($$$)
|
FW_outputChunk($$$)
|
||||||
{
|
{
|
||||||
my ($c, $buf, $d) = @_;
|
my ($hash, $buf, $d) = @_;
|
||||||
$buf = $d->deflate($buf) if($d);
|
$buf = $d->deflate($buf) if($d);
|
||||||
print $c sprintf("%x\r\n", length($buf)), $buf, "\r\n" if(length($buf));
|
addToWritebuffer($hash, sprintf("%x\r\n", length($buf)).$buf."\r\n", "", 1)
|
||||||
|
if(length($buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub
|
sub
|
||||||
@ -1356,7 +1357,6 @@ FW_returnFileAsStream($$$$$)
|
|||||||
my ($path, $suffix, $type, $doEsc, $cacheable) = @_;
|
my ($path, $suffix, $type, $doEsc, $cacheable) = @_;
|
||||||
|
|
||||||
my $etag;
|
my $etag;
|
||||||
my $c = $FW_chash->{CD};
|
|
||||||
|
|
||||||
if($cacheable) {
|
if($cacheable) {
|
||||||
#Check for If-None-Match header (ETag)
|
#Check for If-None-Match header (ETag)
|
||||||
@ -1369,6 +1369,7 @@ FW_returnFileAsStream($$$$$)
|
|||||||
|
|
||||||
$etag = (stat($path))[9]; #mtime
|
$etag = (stat($path))[9]; #mtime
|
||||||
if(defined($etag) && defined($if_none_match) && $etag eq $if_none_match) {
|
if(defined($etag) && defined($if_none_match) && $etag eq $if_none_match) {
|
||||||
|
my $c = $FW_chash->{CD};
|
||||||
print $c "HTTP/1.1 304 Not Modified\r\n",
|
print $c "HTTP/1.1 304 Not Modified\r\n",
|
||||||
$FW_headercors, "\r\n";
|
$FW_headercors, "\r\n";
|
||||||
return -1;
|
return -1;
|
||||||
@ -1386,29 +1387,31 @@ FW_returnFileAsStream($$$$$)
|
|||||||
my $expires = $cacheable ? ("Expires: ".gmtime(time()+900)." GMT\r\n"): "";
|
my $expires = $cacheable ? ("Expires: ".gmtime(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",
|
addToWritebuffer($FW_chash,
|
||||||
$compr, $expires, $FW_headercors, $etag,
|
"HTTP/1.1 200 OK\r\n".
|
||||||
"Transfer-Encoding: chunked\r\n",
|
$compr . $expires . $FW_headercors . $etag .
|
||||||
"Content-Type: $type; charset=$FW_encoding\r\n\r\n";
|
"Transfer-Encoding: chunked\r\n" .
|
||||||
|
"Content-Type: $type; charset=$FW_encoding\r\n\r\n", "", 1);
|
||||||
|
|
||||||
my $d = Compress::Zlib::deflateInit(-WindowBits=>31) if($compr);
|
my $d = Compress::Zlib::deflateInit(-WindowBits=>31) if($compr);
|
||||||
FW_outputChunk($c, $FW_RET, $d);
|
FW_outputChunk($FW_chash, $FW_RET, $d);
|
||||||
my $buf;
|
my $buf;
|
||||||
while(sysread(FH, $buf, 2048)) {
|
while(sysread(FH, $buf, 2048)) {
|
||||||
if($doEsc) { # FileLog special
|
if($doEsc) { # FileLog special
|
||||||
$buf =~ s/</</g;
|
$buf =~ s/</</g;
|
||||||
$buf =~ s/>/>/g;
|
$buf =~ s/>/>/g;
|
||||||
}
|
}
|
||||||
FW_outputChunk($c, $buf, $d);
|
FW_outputChunk($FW_chash, $buf, $d);
|
||||||
}
|
}
|
||||||
close(FH);
|
close(FH);
|
||||||
FW_outputChunk($c, $suffix, $d);
|
FW_outputChunk($FW_chash, $suffix, $d);
|
||||||
|
|
||||||
if($compr) {
|
if($compr) {
|
||||||
$buf = $d->flush();
|
$buf = $d->flush();
|
||||||
print $c sprintf("%x\r\n", length($buf)), $buf, "\r\n" if($buf);
|
addToWritebuffer($FW_chash,sprintf("%x\r\n",length($buf)).$buf."\r\n","",1)
|
||||||
|
if($buf);
|
||||||
}
|
}
|
||||||
print $c "0\r\n\r\n";
|
addToWritebuffer($FW_chash, "0\r\n\r\n", "", 1);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
fhem.pl
4
fhem.pl
@ -3836,7 +3836,7 @@ Debug($) {
|
|||||||
sub
|
sub
|
||||||
addToWritebuffer($$@)
|
addToWritebuffer($$@)
|
||||||
{
|
{
|
||||||
my ($hash, $txt, $callback) = @_;
|
my ($hash, $txt, $callback, $nolimit) = @_;
|
||||||
|
|
||||||
if(defined($hash->{pid})) { # Wont go to the main select in a forked process
|
if(defined($hash->{pid})) { # Wont go to the main select in a forked process
|
||||||
my ($off, $len) = (0, length($txt));
|
my ($off, $len) = (0, length($txt));
|
||||||
@ -3856,7 +3856,7 @@ addToWritebuffer($$@)
|
|||||||
$hash->{WBCallback} = $callback;
|
$hash->{WBCallback} = $callback;
|
||||||
if(!$hash->{$wbName}) {
|
if(!$hash->{$wbName}) {
|
||||||
$hash->{$wbName} = $txt;
|
$hash->{$wbName} = $txt;
|
||||||
} elsif(length($hash->{$wbName}) < 102400) {
|
} elsif($nolimit || length($hash->{$wbName}) < 102400) {
|
||||||
$hash->{$wbName} .= $txt;
|
$hash->{$wbName} .= $txt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user