From 66b636aa90d2dfef92298119df1a9d9f85f8ee8c Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Sun, 11 Sep 2016 21:02:40 -0500 Subject: [PATCH] (GH-746) Use HTTPS if available when HTTP url If the host can be addressed with HTTPS, switch the download url to use HTTPS. --- .../helpers/functions/Get-ChocolateyWebFile.ps1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/chocolatey.resources/helpers/functions/Get-ChocolateyWebFile.ps1 b/src/chocolatey.resources/helpers/functions/Get-ChocolateyWebFile.ps1 index 5c9b5f458d..482eb3f104 100644 --- a/src/chocolatey.resources/helpers/functions/Get-ChocolateyWebFile.ps1 +++ b/src/chocolatey.resources/helpers/functions/Get-ChocolateyWebFile.ps1 @@ -253,6 +253,18 @@ param( throw "This package does not support $bitWidth bit architecture." } + # determine if the url can be SSL/TLS + if ($url.StartsWith('http:')) { + try { + $httpsUrl = $url.Replace("http://", "https://") + Get-WebHeaders -Url $httpsUrl -ErrorAction "Stop" | Out-Null + $url = $httpsUrl + Write-Warning "Url has SSL/TLS available, switching to HTTPS for download" + } catch { + Write-Debug "Url does not have HTTPS available" + } + } + if ($getOriginalFileName) { try { $fileDirectory = [System.IO.Path]::GetDirectoryName($fileFullPath)