Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#1998) Add authorization header to Get-WebFile #1999

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/chocolatey.resources/helpers/functions/Get-WebFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,17 @@ param(
$req.UserAgent = $userAgent
}

if ($options.Headers.Count -gt 0) {
if($options.Headers.Count -gt 0){
Write-Debug "Setting custom headers"
foreach ($item in $options.Headers.GetEnumerator()) {
$uri = (new-object system.uri $url)
Write-Debug($item.Key + ':' + $item.Value)
switch ($item.Key) {
'Accept' {$req.Accept = $item.Value}
'Cookie' {$req.CookieContainer.SetCookies($uri, $item.Value)}
'Referer' {$req.Referer = $item.Value}
'User-Agent' {$req.UserAgent = $item.Value}
Default {$req.Headers.Add($item.Key, $item.Value)}
foreach($key in $options.headers.keys){
$uri = (New-Object -Typename system.uri $url)
switch($key){
'Accept' {$req.Accept = $options.headers.$key}
'Cookie' {$req.CookieContainer.SetCookies($uri,$options.headers.$key)}
'Referer' {$req.Referer = $options.headers.$key}
'User-Agent' {$req.UserAgent = $options.headers.$key}
'Authorization' {$re.Autorization = $options.headers.$key}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accidental misspelling?

Default {$req.Headers.Add($key,$options.headers.$key)}
}
}
}
Expand All @@ -209,7 +209,7 @@ param(

if ($headers.ContainsKey("Content-Type")) {
$contentType = $headers['Content-Type']
if ($contentType -ne $null) {
if ($null -ne $contentType) {
if ($contentType.ToLower().Contains("text/html") -or $contentType.ToLower().Contains("text/plain")) {
Write-Warning "$fileName is of content type $contentType"
Set-Content -Path $binaryIsTextCheckFile -Value "$fileName has content type $contentType" -Encoding UTF8 -Force
Expand Down Expand Up @@ -315,7 +315,7 @@ param(
}
}
} catch {
if ($req -ne $null) {
if ($null -ne $req) {
$req.ServicePoint.MaxIdleTime = 0
$req.Abort();
# ruthlessly remove $req to ensure it isn't reused
Expand All @@ -331,7 +331,7 @@ param(
throw "The remote file either doesn't exist, is unauthorized, or is forbidden for url '$url'. $($_.Exception.Message)"
}
} finally {
if ($res -ne $null) {
if ($null -ne $res) {
$res.Close()
}

Expand Down