From 31e063c2538e7c53de1cafcbb4a87721f9111120 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Mon, 21 Feb 2022 17:12:17 +0000 Subject: [PATCH] 98_update.pm: support encoding unicode (Forum #126088) git-svn-id: https://svn.fhem.de/fhem/trunk@25724 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/98_update.pm | 1 + fhem/FHEM/HttpUtils.pm | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/fhem/FHEM/98_update.pm b/fhem/FHEM/98_update.pm index 7bd68aa11..8ebb3778b 100644 --- a/fhem/FHEM/98_update.pm +++ b/fhem/FHEM/98_update.pm @@ -520,6 +520,7 @@ upd_getUrl($) $url =~ s/%/%25/g; $upd_connecthash{url} = $url; $upd_connecthash{keepalive} = ($url =~ m/localUpdate/ ? 0 : 1); # Forum #49798 + $upd_connecthash{forceEncoding} = "" if($unicodeEncoding); my ($err, $data) = HttpUtils_BlockingGet(\%upd_connecthash); if($err) { uLog 1, $err; diff --git a/fhem/FHEM/HttpUtils.pm b/fhem/FHEM/HttpUtils.pm index ae53b9ff8..e6fc0adc6 100644 --- a/fhem/FHEM/HttpUtils.pm +++ b/fhem/FHEM/HttpUtils.pm @@ -976,9 +976,10 @@ HttpUtils_ParseAnswer($) return ($@, $ret) if($@); } } - my $encoding = ($hash->{httpheader} =~ m/^Content-Type.*charset=(\S*)/im ? - $1 : 'UTF-8'); - $ret = Encode::decode($encoding, $ret) if($unicodeEncoding); + my $encoding = defined($hash->{forceEncoding}) ? $hash->{forceEncoding} : + $hash->{httpheader} =~ m/^Content-Type.*charset=(\S*)/im ? $1 : + 'UTF-8'; + $ret = Encode::decode($encoding, $ret) if($unicodeEncoding && $encoding); # Debug Log3 $hash, $hash->{loglevel}+1, @@ -995,7 +996,7 @@ HttpUtils_ParseAnswer($) # digest(0),hideurl(0),timeout(4),data(""),loglevel(4),header("" or HASH), # noshutdown(1),shutdown(0),httpversion("1.0"),ignoreredirects(0) # method($data?"POST":"GET"),keepalive(0),sslargs({}),user(),pwd() -# compress(1), incrementalTimeout(0) +# compress(1), incrementalTimeout(0), forceEncoding(undef) # Example: # { HttpUtils_NonblockingGet({ url=>"http://fhem.de/MAINTAINER.txt", # callback=>sub($$$){ Log 1,"ERR:$_[1] DATA:".length($_[2]) } }) }