mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-12 02:39:57 +00:00
HttpUtils.pm: activate compression
git-svn-id: https://svn.fhem.de/fhem/trunk@15564 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
eb3c2e95a7
commit
abd709f524
@ -1,5 +1,7 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||||
# Do not insert empty lines here, update check depends on it.
|
# Do not insert empty lines here, update check depends on it.
|
||||||
|
- change: HttpUtils: compression activated
|
||||||
|
disable it with attr global httpcompress 0
|
||||||
- bugfix: 46_SmartPi: fix syntax error bug in Attribut Sub
|
- bugfix: 46_SmartPi: fix syntax error bug in Attribut Sub
|
||||||
- change: 98_dewpoint: Refactoring using API calls, verbose attribute added
|
- change: 98_dewpoint: Refactoring using API calls, verbose attribute added
|
||||||
- change: FileLog removes newlines from the data (Forum #79684)
|
- change: FileLog removes newlines from the data (Forum #79684)
|
||||||
|
@ -496,7 +496,6 @@ upd_getUrl($)
|
|||||||
$url =~ s/%/%25/g;
|
$url =~ s/%/%25/g;
|
||||||
$upd_connecthash{url} = $url;
|
$upd_connecthash{url} = $url;
|
||||||
$upd_connecthash{keepalive} = ($url =~ m/localUpdate/ ? 0 : 1); # Forum #49798
|
$upd_connecthash{keepalive} = ($url =~ m/localUpdate/ ? 0 : 1); # Forum #49798
|
||||||
# $upd_connecthash{compress} = 1; # fhem.de does not support compression
|
|
||||||
my ($err, $data) = HttpUtils_BlockingGet(\%upd_connecthash);
|
my ($err, $data) = HttpUtils_BlockingGet(\%upd_connecthash);
|
||||||
if($err) {
|
if($err) {
|
||||||
uLog 1, $err;
|
uLog 1, $err;
|
||||||
|
@ -82,6 +82,7 @@ HttpUtils_Close($)
|
|||||||
delete($hash->{hu_port});
|
delete($hash->{hu_port});
|
||||||
delete($hash->{directReadFn});
|
delete($hash->{directReadFn});
|
||||||
delete($hash->{directWriteFn});
|
delete($hash->{directWriteFn});
|
||||||
|
delete($hash->{compress});
|
||||||
}
|
}
|
||||||
|
|
||||||
sub
|
sub
|
||||||
@ -342,6 +343,17 @@ HttpUtils_Connect($)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if((!defined($hash->{compress}) || $hash->{compress}) &&
|
||||||
|
AttrVal("global", "httpcompress", 1)) {
|
||||||
|
if(!defined($HU_use_zlib)) {
|
||||||
|
$HU_use_zlib = 1;
|
||||||
|
eval { require Compress::Zlib; };
|
||||||
|
$HU_use_zlib = 0 if($@);
|
||||||
|
}
|
||||||
|
$hash->{compress} = $HU_use_zlib;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return HttpUtils_Connect2($hash) if($hash->{conn} && $hash->{keepalive});
|
return HttpUtils_Connect2($hash) if($hash->{conn} && $hash->{keepalive});
|
||||||
|
|
||||||
if($hash->{callback}) { # Nonblocking staff
|
if($hash->{callback}) { # Nonblocking staff
|
||||||
@ -409,15 +421,6 @@ HttpUtils_Connect($)
|
|||||||
if(!$hash->{conn});
|
if(!$hash->{conn});
|
||||||
}
|
}
|
||||||
|
|
||||||
if($hash->{compress}) {
|
|
||||||
if(!defined($HU_use_zlib)) {
|
|
||||||
$HU_use_zlib = 1;
|
|
||||||
eval { require Compress::Zlib; };
|
|
||||||
$HU_use_zlib = 0 if($@);
|
|
||||||
}
|
|
||||||
$hash->{compress} = $HU_use_zlib;
|
|
||||||
}
|
|
||||||
|
|
||||||
return HttpUtils_Connect2($hash);
|
return HttpUtils_Connect2($hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -530,7 +533,8 @@ HttpUtils_Connect2($)
|
|||||||
$hdr .= "Connection: Close\r\n"
|
$hdr .= "Connection: Close\r\n"
|
||||||
if($httpVersion ne "1.0" && !$hash->{keepalive});
|
if($httpVersion ne "1.0" && !$hash->{keepalive});
|
||||||
|
|
||||||
$hdr .= "Authorization: Basic ".encode_base64($hash->{user}.":".$hash->{pwd}, "")."\r\n"
|
$hdr .= "Authorization: Basic ".
|
||||||
|
encode_base64($hash->{user}.":".$hash->{pwd}, "")."\r\n"
|
||||||
if($hash->{auth} && !$hash->{digest} &&
|
if($hash->{auth} && !$hash->{digest} &&
|
||||||
!($hash->{header} &&
|
!($hash->{header} &&
|
||||||
$hash->{header} =~ /^Authorization:\s*Digest/mi));
|
$hash->{header} =~ /^Authorization:\s*Digest/mi));
|
||||||
@ -807,6 +811,11 @@ HttpUtils_ParseAnswer($)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($hash->{httpheader} =~ /^Content-Encoding: gzip/mi && $HU_use_zlib) {
|
||||||
|
eval { $ret = Compress::Zlib::memGunzip($ret) };
|
||||||
|
return ($@, $ret) if($@);
|
||||||
|
}
|
||||||
|
|
||||||
# Debug
|
# Debug
|
||||||
Log3 $hash, $hash->{loglevel}+1,
|
Log3 $hash, $hash->{loglevel}+1,
|
||||||
"HttpUtils $hash->{displayurl}: Got data, length: ". length($ret);
|
"HttpUtils $hash->{displayurl}: Got data, length: ". length($ret);
|
||||||
@ -822,8 +831,9 @@ HttpUtils_ParseAnswer($)
|
|||||||
# digest(0),hideurl(0),timeout(4),data(""),loglevel(4),header("" or HASH),
|
# digest(0),hideurl(0),timeout(4),data(""),loglevel(4),header("" or HASH),
|
||||||
# noshutdown(1),shutdown(0),httpversion("1.0"),ignoreredirects(0)
|
# noshutdown(1),shutdown(0),httpversion("1.0"),ignoreredirects(0)
|
||||||
# method($data?"POST":"GET"),keepalive(0),sslargs({}),user(),pwd()
|
# method($data?"POST":"GET"),keepalive(0),sslargs({}),user(),pwd()
|
||||||
|
# compress(1)
|
||||||
# Example:
|
# Example:
|
||||||
# { HttpUtils_NonblockingGet({ url=>"http://www.google.de/",
|
# { HttpUtils_NonblockingGet({ url=>"http://fhem.de/MAINTAINER.txt",
|
||||||
# callback=>sub($$$){ Log 1,"ERR:$_[1] DATA:".length($_[2]) } }) }
|
# callback=>sub($$$){ Log 1,"ERR:$_[1] DATA:".length($_[2]) } }) }
|
||||||
sub
|
sub
|
||||||
HttpUtils_NonblockingGet($)
|
HttpUtils_NonblockingGet($)
|
||||||
|
@ -1448,6 +1448,13 @@ The following local attributes are used by a wider range of devices:
|
|||||||
OS implementation (inet_aton and gethostbyname) will be used.
|
OS implementation (inet_aton and gethostbyname) will be used.
|
||||||
</li><br>
|
</li><br>
|
||||||
|
|
||||||
|
<a name="featurelevel"></a>
|
||||||
|
<li>featurelevel<br>
|
||||||
|
Enable/disable old or new features, based on FHEM version.
|
||||||
|
E.g. the $value hash for notify is only set for featurelevel up to 5.6,
|
||||||
|
as it is deprecated, use the Value() function instead.
|
||||||
|
</li><br>
|
||||||
|
|
||||||
<a name="holiday2we"></a>
|
<a name="holiday2we"></a>
|
||||||
<li>holiday2we<br>
|
<li>holiday2we<br>
|
||||||
If this attribute is set, then the <a href="#perl">$we</a> variable
|
If this attribute is set, then the <a href="#perl">$we</a> variable
|
||||||
@ -1459,11 +1466,10 @@ The following local attributes are used by a wider range of devices:
|
|||||||
</ul>
|
</ul>
|
||||||
</li><br>
|
</li><br>
|
||||||
|
|
||||||
<a name="featurelevel"></a>
|
<a name="httpcompress"></a>
|
||||||
<li>featurelevel<br>
|
<li>httpcompress<br>
|
||||||
Enable/disable old or new features, based on FHEM version.
|
the HttpUtils module is used by a lot of FHEM modules, and enables
|
||||||
E.g. the $value hash for notify is only set for featurelevel up to 5.6,
|
compression by default. Set httpcompress to 0 to disable this feature.
|
||||||
as it is deprecated, use the Value() function instead.
|
|
||||||
</li><br>
|
</li><br>
|
||||||
|
|
||||||
<a name="logdir"></a>
|
<a name="logdir"></a>
|
||||||
|
@ -1541,6 +1541,13 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
|||||||
bzw gethostbyname aufgerufen.
|
bzw gethostbyname aufgerufen.
|
||||||
</li><br>
|
</li><br>
|
||||||
|
|
||||||
|
<a name="featurelevel"></a>
|
||||||
|
<li>featurelevel<br>
|
||||||
|
Aktiviere bzw. deaktiviere bestimmte alte oder neue Funktionen, basierend
|
||||||
|
auf die FHEM Version. Z.Bsp. das $value hash für notify wird nur bis featurelevel 5.6
|
||||||
|
befüllt, da es unerwünscht ist. Stattdessen sollte man die
|
||||||
|
Value() Funktion verwenden.
|
||||||
|
</li><br>
|
||||||
|
|
||||||
<a name="holiday2we"></a>
|
<a name="holiday2we"></a>
|
||||||
<li>holiday2we<br>
|
<li>holiday2we<br>
|
||||||
@ -1554,12 +1561,11 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
|||||||
</ul>
|
</ul>
|
||||||
</li><br>
|
</li><br>
|
||||||
|
|
||||||
<a name="featurelevel"></a>
|
<a name="httpcompress"></a>
|
||||||
<li>featurelevel<br>
|
<li>httpcompress<br>
|
||||||
Aktiviere bzw. deaktiviere bestimmte alte oder neue Funktionen, basierend
|
das HttpUtils Modul wird von etlichen FHEM modulen verwendet und
|
||||||
auf die FHEM Version. Z.Bsp. das $value hash für notify wird nur bis featurelevel 5.6
|
aktiviert Komprimierung in der Voreinstellung. Falls man
|
||||||
befüllt, da es unerwünscht ist. Stattdessen sollte man die
|
httpcompress auf 0 setzt, wird die Komprimierung deaktiviert.
|
||||||
Value() Funktion verwenden.
|
|
||||||
</li><br>
|
</li><br>
|
||||||
|
|
||||||
<a name="logdir"></a>
|
<a name="logdir"></a>
|
||||||
|
@ -301,9 +301,10 @@ my @globalAttrList = qw(
|
|||||||
dnsServer
|
dnsServer
|
||||||
dupTimeout
|
dupTimeout
|
||||||
exclude_from_update
|
exclude_from_update
|
||||||
featurelevel
|
featurelevel:5.5,5.6,5.7,5,8,99.99
|
||||||
genericDisplayType:switch,outlet,light,blind,speaker,thermostat
|
genericDisplayType:switch,outlet,light,blind,speaker,thermostat
|
||||||
holiday2we
|
holiday2we
|
||||||
|
httpcompress:0,1
|
||||||
language:EN,DE
|
language:EN,DE
|
||||||
lastinclude
|
lastinclude
|
||||||
latitude
|
latitude
|
||||||
|
Loading…
x
Reference in New Issue
Block a user