You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow Web Cmdlets to Ignore HTTP Error Statuses (PowerShell#10466)
* Add -SkipHttpErrorCheck to web request cmdlets
The -SkipHttpErrorCheck flag causes web request cmdlets
(Invoke-WebRequest and Invoke-RestMethod) to ignore HTTP statuses that
are error statuses and treat them as successful requests. This allows
users to handle the responses using their own error handler and gives
them access to the full, unmodified response body and headers.
* Add -ResponseStatusVariable to Invoke-RestMethod
This allows the user to specify a variable to set to the integer value
of the respons's status code, Analogous to using
-ResponseHeadersVariable to retrieve the headers of the response. This
can be used to distinguish error messages from success messages when
used with -SkipHttpErrorCheck.
* Fix coding-style error
The summary for the SkipHttpErrorCheck property didn't conform
to style guidelines. This changes the summary to start with
"Gets or sets".
* Add tests for -SkipHttpErrorCheck
This flag supresses terminating errors on web cmdlets.
The tests are written to check that it properly
supressed the errors.
* Add test for -StatusCodeVariable
Th -StatusCodeVariable parameter specifies an output
variable for the status code with Invoke-RestMethod.
This test makes sure it functions properly.
* Fix typos and style for -SkipHttpErrorCheck tests
Variables had different cases from each other and some parameter
names were lower case.
* Fix typos and style for -StatusCodeVariable test
Variables had different cases from each other and some parameter
names were lower case.
* Add failure tests when missing -SkipHttpErrorCheck
These tests ensure that Web Cmdlets fail when -SkipHttpErrorCheck
is missing.
* Clean up tests for -SkipHttpErrorCheck
Per discussion on the pull requests. This commit fixes up
style problems with the tests for -SkipHttpErrorCheck.
* Add more status tests for -StatusCodeVariable
Previously, the -StatusCodeVariable flag in Invoke-RestMethod
only had tests for 200 status. This commit adds tests for 404
and 500 statuses and removes -SkipHttpErrorCheck from the 200
check.
* Fix response body in -StatusCodeVariable test
The test was copy/pastes from the 200 status test. The body
indicated success. This commit fixes that so it is also an
error indicator.
Copy file name to clipboardExpand all lines: src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs
+12Lines changed: 12 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -75,6 +75,12 @@ public int MaximumFollowRelLink
75
75
[Alias("RHV")]
76
76
publicstringResponseHeadersVariable{get;set;}
77
77
78
+
/// <summary>
79
+
/// Gets or sets the variable name to use for storing the status code from the response.
It "Validates Invoke-WebRequest with -PreserveAuthorizationOnRedirect preserves the authorization header on redirect: <redirectType> <redirectedMethod>"-TestCases $redirectTests {
It "Validates Invoke-RestMethod with -PreserveAuthorizationOnRedirect preserves the authorization header on redirect: <redirectType> <redirectedMethod>"-TestCases $redirectTests {
@@ -3387,4 +3477,3 @@ Describe "Web cmdlets tests using the cmdlet's aliases" -Tags "CI", "RequireAdmi
0 commit comments