2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

HttpUtils: add proxyAuth (Forum #60471)

git-svn-id: https://svn.fhem.de/fhem/trunk@15033 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2017-09-09 10:20:16 +00:00
parent bb36ecf8e0
commit 682baf5753
4 changed files with 18 additions and 2 deletions

View File

@ -392,6 +392,7 @@ sub
HttpUtils_Connect2($)
{
my ($hash) = @_;
my $usingSSL;
$hash->{host} =~ s/:.*//;
if($hash->{protocol} eq "https" && $hash->{conn} && !$hash->{hu_sslAdded}) {
@ -403,11 +404,13 @@ HttpUtils_Connect2($)
return $errstr;
} else {
$hash->{conn}->blocking(1);
$usingSSL = 1;
if($hash->{hu_proxy}) { # can block!
my $pw = AttrVal("global", "proxyAuth", "");
$pw = "Proxy-Authorization: Basic $pw\r\n" if($pw);
my $hdr = "CONNECT $hash->{host}:$hash->{hu_port} HTTP/1.0\r\n".
"User-Agent: fhem\r\n".
"\r\n";
"User-Agent: fhem\r\n$pw\r\n";
syswrite $hash->{conn}, $hdr;
my $buf;
my $len = sysread($hash->{conn},$buf,65536);
@ -504,6 +507,10 @@ HttpUtils_Connect2($)
$hdr .= "Content-Type: application/x-www-form-urlencoded\r\n"
if ($hdr !~ "Content-Type:");
}
if(!$usingSSL) {
my $pw = AttrVal("global", "proxyAuth", "");
$hdr .= "Proxy-Authorization: Basic $pw\r\n" if($pw);
}
Log3 $hash, $hash->{loglevel}+1, "HttpUtils request header:\n$hdr";
$hdr .= "\r\n";

View File

@ -1519,6 +1519,10 @@ The following local attributes are used by a wider range of devices:
<li>proxy<br>
IP:PORT of the proxy server to be used by HttpUtils.
</li><br>
<a name="proxyAuth"></a>
<li>proxyAuth<br>
Base64 encoded username:password
</li><br>
<a name="proxyExclude"></a>
<li>proxyExclude<br>
regexp for hosts to exclude when using a proxy

View File

@ -1622,6 +1622,10 @@ Die folgenden lokalen Attribute werden von mehreren Ger&auml;ten verwendet:
<li>proxy<br>
IP:PORT des proxy Servers, wird von HttpUtils benutzt.
</li><br>
<a name="proxyAuth"></a>
<li>proxyAuth<br>
Base64 kodiertes Benutzername:Passwort
</li><br>
<a name="proxyExclude"></a>
<li>proxyExclude<br>
Regexp, um bestimmte Hosts nicht via proxy zu kontaktieren.

View File

@ -309,6 +309,7 @@ my @globalAttrList = qw(
perlSyntaxCheck:0,1
pidfilename
proxy
proxyAuth
proxyExclude
restartDelay
restoreDirs