Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
Perform download url check with HTTP headers from chocolateyInstall.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
galeksandrp committed Mar 25, 2018
1 parent 71f792f commit 4faefd0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions AU/Private/check_url.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Returns nothing if url is valid, error otherwise
function check_url( [string] $Url, [int]$Timeout, $ExcludeType='text/html' ) {
function check_url( [string] $Url, [int]$Timeout, $ExcludeType='text/html', $Options ) {
if (!(is_url $Url)) { return "URL syntax is invalid" }

try
{
$response = request $url $Timeout
$response = request $url $Timeout -Options $Options
if ($response.ContentType -like "*${ExcludeType}*") { return "Bad content type '$ExcludeType'" }
}
catch {
Expand Down
3 changes: 2 additions & 1 deletion AU/Private/request.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
function request( [string]$Url, [int]$Timeout ) {
function request( [string]$Url, [int]$Timeout, $Options ) {
if ([string]::IsNullOrWhiteSpace($url)) {throw 'The URL is empty'}
$request = [System.Net.WebRequest]::Create($Url)
if ($Timeout) { $request.Timeout = $Timeout*1000 }
if ($Options.Headers) { $Options.Headers.Keys | %{ $request.Headers.add($_, $Options.Headers[$_]) } }

$response = $request.GetResponse()
$response.Close()
Expand Down
2 changes: 1 addition & 1 deletion AU/Public/Update-Package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function Update-Package {
"URL check" | result
$Latest.Keys | ? {$_ -like 'url*' } | % {
$url = $Latest[ $_ ]
if ($res = check_url $url) { throw "${res}:$url" } else { " $url" | result }
if ($res = check_url $url -Options $Latest.Options) { throw "${res}:$url" } else { " $url" | result }
}
}

Expand Down

0 comments on commit 4faefd0

Please sign in to comment.