From d10d64864fe6aa9f75edf1cc7537188d72f0082c Mon Sep 17 00:00:00 2001 From: arika Date: Thu, 4 Jul 2024 23:31:55 +0900 Subject: [PATCH] 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. --- externals/install-dotnet.ps1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/externals/install-dotnet.ps1 b/externals/install-dotnet.ps1 index 44d365c..5d423d2 100644 --- a/externals/install-dotnet.ps1 +++ b/externals/install-dotnet.ps1 @@ -416,6 +416,13 @@ function GetHTTPResponse([Uri] $Uri, [bool]$HeaderOnly, [bool]$DisableRedirect, UseDefaultCredentials=$ProxyUseDefaultCredentials; 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) {