Skip to content

Commit

Permalink
(GH-1141) Fix: Constant Proxy Null Reference Error
Browse files Browse the repository at this point in the history
In some environments, (new-object System.Net.WebClient).Proxy -eq $null
is true, as is [System.Net.WebRequest]::DefaultWebProxy -eq $null. This
means the IsBypassed() method was being called on a null object. This
checks the object's existence before using that method.
  • Loading branch information
brianary authored and ferventcoder committed Feb 17, 2017
1 parent c873be5 commit eb39536
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/chocolatey.resources/helpers/functions/Get-WebFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ param(
Write-Host "Using explicit proxy server '$explicitProxy'."
$req.Proxy = $proxy

} elseif (!$webclient.Proxy.IsBypassed($url))
} elseif ($webclient.Proxy -and !$webclient.Proxy.IsBypassed($url))
{
# system proxy (pass through)
$creds = [net.CredentialCache]::DefaultCredentials
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ param(
Write-Debug "Using explicit proxy server '$explicitProxy'."
$request.Proxy = $proxy

} elseif (!$client.Proxy.IsBypassed($url))
} elseif ($client.Proxy -and !$client.Proxy.IsBypassed($url))
{
# system proxy (pass through)
$creds = [Net.CredentialCache]::DefaultCredentials
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ param(
Write-Host "Using explicit proxy server '$explicitProxy'."
$request.Proxy = $proxy

} elseif (!$client.Proxy.IsBypassed($url))
} elseif ($client.Proxy -and !$client.Proxy.IsBypassed($url))
{
# system proxy (pass through)
$creds = [Net.CredentialCache]::DefaultCredentials
Expand Down

0 comments on commit eb39536

Please sign in to comment.