-
Notifications
You must be signed in to change notification settings - Fork 931
Request headers in Get-WebHeaders
#1733
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
Closed
galeksandrp
wants to merge
1
commit into
chocolatey:master
from
galeksandrp:request-headers-in-get-webheaders
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,9 @@ command line'. | |
.PARAMETER IgnoredArguments | ||
Allows splatting with arguments that do not apply. Do not use directly. | ||
|
||
.PARAMETER Options | ||
Specify request headers. Please note that UserAgent function parameter, if specified, overwrite header present in this parameter. | ||
|
||
.LINK | ||
Get-ChocolateyWebFile | ||
|
||
|
@@ -54,8 +57,9 @@ Get-WebFile | |
#> | ||
param( | ||
[parameter(Mandatory=$false, Position=0)][string] $url = '', | ||
[parameter(Mandatory=$false, Position=1)][string] $userAgent = 'chocolatey command line', | ||
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments | ||
[parameter(Mandatory=$false, Position=1)][string] $userAgent, | ||
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments, | ||
[parameter(Mandatory=$false)][hashtable] $options = @{Headers=@{}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be before $ignoredArguments. Those are the last items to be passed. |
||
) | ||
|
||
Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters | ||
|
@@ -127,7 +131,25 @@ param( | |
|
||
#http://stackoverflow.com/questions/518181/too-many-automatic-redirections-were-attempted-error-message-when-using-a-httpw | ||
$request.CookieContainer = New-Object System.Net.CookieContainer | ||
if ($userAgent -ne $null) { | ||
|
||
#Mimic previous behaviour with default User-Agent | ||
$request.UserAgent = 'chocolatey command line' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Formatting please |
||
|
||
if ($Options.Headers) { | ||
$Options.Headers.Keys | % { | ||
if ([System.Net.WebHeaderCollection]::IsRestricted($_)) { | ||
$key = $_.Replace('-','') | ||
$request.$key = $Options.Headers[$_] | ||
} | ||
else { | ||
$request.Headers.add($_, $Options.Headers[$_]) | ||
} | ||
} | ||
} | ||
|
||
#User-Agent, if specified explicitly as function parameter, should overwrite header from Headers hashtable | ||
#`$userAgent` is typed parameter, when it's not passed value is '' (empty string) | ||
if ($userAgent -ne '') { | ||
Write-Debug "Setting the UserAgent to `'$userAgent`'" | ||
$request.UserAgent = $userAgent | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also specify the first version this was available in. I would venture a guess that it is 0.10.13. At least include that here (search other parameters for examples of this and keep it consistent.). Thanks!