GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Add Multipart Support to Web Cmdlets by markekraus · Pull Request #4782 · PowerShell/PowerShell Conversation
|
|
Mark Kraus (@markekraus), |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
CI Rerun count: I
72a3636 to
0796005
Compare
| else if (content is MultipartFormDataContent) | ||
| { | ||
| WebSession.ContentHeaders.Clear(); | ||
| MultipartFormDataContent multipartFormDataContent = content as MultipartFormDataContent; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We should exclude double casting. Here it is better use C# 7.0 pattern:
else if (content is MultipartFormDataContent multipartFormDataContent )
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Awesome. I will do that.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (request == null) | ||
| throw new ArgumentNullException("request"); | ||
| if (multipartContent == null) | ||
| throw new ArgumentNullException("multipartContent"); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We should use curly braces:
if ( ... ) { ... }
or single line operator.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I can do this, but it will not match the surrounding code.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I believe we should use approved patterns for new code.
You can wait a view of other maintainers.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I agreed with Ilya (@iSazonov). The new code is somewhat isolated as it's in its own method, so I think it's fine to use the more preferred style.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Dongbo Wang (@daxian-dbw) Awesome! format is already corrected in the most recent commit for this PR.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
| public ActionResult Index() | ||
| { | ||
|
|
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please remove extra line.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
will do
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| Context "Multipart/form-data Tests" { | ||
| It "Verifies Invoke-WebRequest Supports Multipart String Values" { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We use the same Context header 😕
I believe we should add cmdlet name Context "Invoke-WebRequest Multipart/form-data Tests"
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes, because they are under different describe blocks. We did the same thing with HTTPS
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think it's somewhat confusing, but we can leave it for Context.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
For clarity, would you like me to change it or leave it as is?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Leave it as is.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| Context "Multipart/form-data Tests" { | ||
| It "Verifies Invoke-RestMethod Supports Multipart String Values" { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Context "Invoke-RestMethod Multipart/form-data Tests"
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Mark Kraus (@markekraus) Thank you for the good work! Could you please take a look at the 2 comments I left?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
| else if (content is MultipartFormDataContent multipartFormDataContent) | ||
| { | ||
| WebSession.ContentHeaders.Clear(); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
WebSession.ContentHeader is set at line 325 when ContentType is specified. Is it OK to ignore that as well?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes, ContentType must be set by the MultipartFormDataContent object as it controls the boundary in the Content-Type header used to distinguish between the various fields supplied. Documentation will probably need to make clear that -ContentType will be ignored when a MultipartFormDataContent object is supplied. It doesn't make sense to use any other Content-Type header when doing multipart/form-data anyway. If this isn't done here, the Foreach on line 421 throws. when Content is set with a MultipartFormDataContent it overwrites all the content headers, so trying to add content headers again causes an exception about ContentType already existing.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification. I updated the PR description to capture your words.
Then there is a potential problem at line 239
Nevermind, GetRequest happens before FillRequestStream, so we are good. Updated the PR description to mention -Header and -WebSession will be ignored as well.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| $fileContent.Headers.ContentType = [System.Net.Http.Headers.MediaTypeHeaderValue]::Parse("text/plain") | ||
| $multipartContent.Add($fileContent) | ||
| } | ||
| # unary comma required |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
nit: can you please also mention why it's required -- $multipartContent will be unwrapped/enumerated otherwise.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
fixed
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Mark Kraus (@markekraus) Thanks again for the good work! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Dongbo Wang (@daxian-dbw) For documentation, when is that handled? Should I submit a PR/Issue to PowerShell-Docs now or does it need to wait for the next beta release? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Yes, you are welcome to submit a PR to PowerShell-Docs now :)
Please see https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#contributing-to-documentation for more details |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Partially implements PowerShell#2112 - Adds `System.Net.Http.MultipartFormDataContent` as a possible type for `-Body` - Adds `/Multipart/` test to WebListener This allows for the user to create their own `Http.MultipartFormDataContent` object and submit it. Since `multipart/form-data` submissions are highly flexible, adding direct support for it to the CmdLets may over-complicate the command parameters and a limited implementation would not address the broad scope of use cases. This at least allows the user to submit multipart forms using the Web Cmdlets and not have to manage their own `HttpClient`. Once this is introduced, limited multipart implementations can be expanded to use the code in this PR.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.