feat: use ProxyAddress with Credential when passed to powershell script

In a proxy environment, such as in an enterprise, HTTP(S)_PROXY often takes the form of credentials, i.e., http://user:pass@host:port. 
When $ProxyAddress is passed in this format, WebProxy does not use the authentication information by default.
This PR aims to solve the above problem.
This commit is contained in:
arika 2024-07-04 23:31:55 +09:00 committed by GitHub
parent 5d1464d5da
commit d10d64864f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -416,6 +416,13 @@ function GetHTTPResponse([Uri] $Uri, [bool]$HeaderOnly, [bool]$DisableRedirect,
UseDefaultCredentials=$ProxyUseDefaultCredentials; UseDefaultCredentials=$ProxyUseDefaultCredentials;
BypassList = $ProxyBypassList; BypassList = $ProxyBypassList;
} }
# If ProxyAddress is contained username and password, then set credentials
# e.g. http://(user):(pass)@...
if ($ProxyAddress -match '://(.*?):(.*?)@') {
$proxyUsername = $matches[1]
$proxyPassword = $matches[2]
$HttpClientHandler.Proxy.Credentials = New-Object System.Net.NetworkCredential($proxyUsername, $proxyPassword)
}
} }
if ($DisableRedirect) if ($DisableRedirect)
{ {