Merge pull request #7676 from johnbeisner/master
Skip DefaultProxy resolution code if an exception is thrown
This commit is contained in:
commit
2956c548b9
1 changed files with 17 additions and 12 deletions
21
scripts/obtain/dotnet-install.ps1
vendored
21
scripts/obtain/dotnet-install.ps1
vendored
|
@ -172,33 +172,38 @@ function GetHTTPResponse([Uri] $Uri)
|
||||||
# HttpClient is used vs Invoke-WebRequest in order to support Nano Server which doesn't support the Invoke-WebRequest cmdlet.
|
# HttpClient is used vs Invoke-WebRequest in order to support Nano Server which doesn't support the Invoke-WebRequest cmdlet.
|
||||||
Load-Assembly -Assembly System.Net.Http
|
Load-Assembly -Assembly System.Net.Http
|
||||||
|
|
||||||
if(-not $ProxyAddress)
|
if( -not $ProxyAddress) {
|
||||||
{
|
try {
|
||||||
# Despite no proxy being explicitly specified, we may still be behind a default proxy
|
# Despite no proxy being explicitly specified, we may still be behind a default proxy
|
||||||
$DefaultProxy = [System.Net.WebRequest]::DefaultWebProxy;
|
$DefaultProxy = [System.Net.WebRequest]::DefaultWebProxy;
|
||||||
if($DefaultProxy -and (-not $DefaultProxy.IsBypassed($Uri))){
|
if($DefaultProxy -and (-not $DefaultProxy.IsBypassed($Uri))) {
|
||||||
$ProxyAddress = $DefaultProxy.GetProxy($Uri).OriginalString
|
$ProxyAddress = $DefaultProxy.GetProxy($Uri).OriginalString
|
||||||
$ProxyUseDefaultCredentials = $true
|
$ProxyUseDefaultCredentials = $true
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
# Eat the exception and move forward as the above code is an attempt
|
||||||
|
# at resolving the DefaultProxy that may not have been a problem.
|
||||||
|
$ProxyAddress = $null
|
||||||
|
Say-Verbose("Exception ignored: $_.Exception.Message - moving forward...")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($ProxyAddress){
|
if($ProxyAddress) {
|
||||||
$HttpClientHandler = New-Object System.Net.Http.HttpClientHandler
|
$HttpClientHandler = New-Object System.Net.Http.HttpClientHandler
|
||||||
$HttpClientHandler.Proxy = New-Object System.Net.WebProxy -Property @{Address=$ProxyAddress;UseDefaultCredentials=$ProxyUseDefaultCredentials}
|
$HttpClientHandler.Proxy = New-Object System.Net.WebProxy -Property @{Address=$ProxyAddress;UseDefaultCredentials=$ProxyUseDefaultCredentials}
|
||||||
$HttpClient = New-Object System.Net.Http.HttpClient -ArgumentList $HttpClientHandler
|
$HttpClient = New-Object System.Net.Http.HttpClient -ArgumentList $HttpClientHandler
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
$HttpClient = New-Object System.Net.Http.HttpClient
|
$HttpClient = New-Object System.Net.Http.HttpClient
|
||||||
}
|
}
|
||||||
# Default timeout for HttpClient is 100s. For a 50 MB download this assumes 500 KB/s average, any less will time out
|
# Default timeout for HttpClient is 100s. For a 50 MB download this assumes 500 KB/s average, any less will time out
|
||||||
# 10 minutes allows it to work over much slower connections.
|
# 10 minutes allows it to work over much slower connections.
|
||||||
$HttpClient.Timeout = New-TimeSpan -Minutes 10
|
$HttpClient.Timeout = New-TimeSpan -Minutes 10
|
||||||
$Response = $HttpClient.GetAsync($Uri).Result
|
$Response = $HttpClient.GetAsync($Uri).Result
|
||||||
if (($Response -eq $null) -or (-not ($Response.IsSuccessStatusCode)))
|
if (($Response -eq $null) -or (-not ($Response.IsSuccessStatusCode))) {
|
||||||
{
|
|
||||||
$ErrorMsg = "Failed to download $Uri."
|
$ErrorMsg = "Failed to download $Uri."
|
||||||
if ($Response -ne $null)
|
if ($Response -ne $null) {
|
||||||
{
|
|
||||||
$ErrorMsg += " $Response"
|
$ErrorMsg += " $Response"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue