Fixes Invoke-RestMethod -PassThru -Outfile writing to file.#24086
Merged
daxian-dbw merged 3 commits intoPowerShell:masterfrom Aug 5, 2024
Merged
Fixes Invoke-RestMethod -PassThru -Outfile writing to file.#24086daxian-dbw merged 3 commits intoPowerShell:masterfrom
daxian-dbw merged 3 commits intoPowerShell:masterfrom
Conversation
iSazonov
reviewed
Jul 25, 2024
| // Saves the response stream to a file. If piped then the response stream needs to be rewinded. | ||
| if (responseStream != null) | ||
| { | ||
| responseStream.Position = 0; |
Collaborator
There was a problem hiding this comment.
I suggest to use the same code pattern we used for Invoke-WebRequest
Collaborator
Author
There was a problem hiding this comment.
Thank you for the suggestion! It took me one more look to realize how similar it can be. Changes made.
daxian-dbw
requested changes
Aug 1, 2024
...erShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs
Show resolved
Hide resolved
daxian-dbw
approved these changes
Aug 5, 2024
chrisdent-de
pushed a commit
to chrisdent-de/PowerShell
that referenced
this pull request
Sep 12, 2024
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PR Summary
Fixes: #15409
When piping the stream is run to the end and the saved file size ends up being 0.
I added checks to see if a pipe was called then rewinded the stream.
If not piping, just save the stream in the file.
Wtih Invoke-RestMethod there isn't a consistent object returned when piped thru. The object can be a PSCustomObject, String, XML, or Json. So adding an OutFile like WebResponseObject is not feasible unless a new class is written for RestMethod like WebRequestObject.
PR Context
This fixes the issue where Invoke-RestMethod -PassThru -OutFile ends up not writing to file.
This issue is related to #21082.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.- [ ] Issue filed:
(which runs in a different PS Host).