-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Extend -SkipHeaderValidation to include -UserAgent to support non-standard User-Agent headers #4479
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
Extend -SkipHeaderValidation to include -UserAgent to support non-standard User-Agent headers #4479
Conversation
@markekraus, |
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.
Thanks for the contribution, just one requested change
|
||
try { | ||
if ($Cmdlet -eq 'Invoke-WebRequest') { | ||
$result.Output = Invoke-WebRequest -Uri $Uri -TimeoutSec 5 -UserAgent $UserAgent -SkipHeaderValidation:$SkipHeaderValidation.IsPresent |
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.
Instead of duplicating all the parameters, you should use splatting:
$args = @{Uri=$uri;Timeout=5;UserAgent=$useragent;...}
Invoke-WebRequest @args
Invoke-RestMethod @args
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.
Used $Params
instead of $args
to avoid conflicts with the automatic variable.
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.
LGTM
Synopsis
Extends #4085 to include the
-UserAgent
parameter suppliedUser-Agent
header.Description
Some API's, such as Reddit require special
User-Agent
headers to identify application consumers of the API. Currently,Invoke-WebRequest
andInvoke-RestMethod
are unable to properly use non-compliantUser-Agent
headers. This extends the behavior of the-SkipHeaderValidation
switch parameter to include theUser-Agent
header supplied by the-UserAgent
parameter.Test Code
Current Behavior:
New Behavior