Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add support for Content Headers to BasicHtmlWebResponseObject and HtmlWebResponseObject#4494

Merged
TravisEz13 merged 4 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
markekraus:GetRawContentHeadermarkekraus/PowerShell:GetRawContentHeaderCopy head branch name to clipboard
Aug 21, 2017
Merged

Add support for Content Headers to BasicHtmlWebResponseObject and HtmlWebResponseObject#4494
TravisEz13 merged 4 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
markekraus:GetRawContentHeadermarkekraus/PowerShell:GetRawContentHeaderCopy head branch name to clipboard

Conversation

@markekraus

@markekraus markekraus commented Aug 4, 2017

Copy link
Copy Markdown
Contributor

Fixes #4467

System.Net.Http.HttpResponseMessage has split the Content headers from the Response headers. This split appears to be intentional and permanent. This split results in the Content-Type and Content-Length headers to be missing from the WebResponseObject.Headers dictionary and from the RawContent property of BasicHtmlWebResponseObject and HtmlWebResponseObject.

This adds the Content headers back to those locations to make it similar to 5.1.

This also adds support to RawContent for multiple response headers with the same field name. System.Net.Http.Headers.HttpContentHeaders and System.Net.Http.Headers.HttpResponseHeaders implement values as arrays.

@msftclas

msftclas commented Aug 4, 2017

Copy link
Copy Markdown

@markekraus,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by Microsoft. We will now review your pull request.
Thanks,
Microsoft Pull Request Bot

@iSazonov

iSazonov commented Aug 5, 2017

Copy link
Copy Markdown
Collaborator

@markekraus Could you please add tests?

@markekraus

Copy link
Copy Markdown
Contributor Author

@iSazonov Tests Added. I wasn't exactly sure what tests to add. There is already significant validation being done on the Headers and RawContent properties. If I need more than these 2 tests please let me know.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo Wen

@markekraus

Copy link
Copy Markdown
Contributor Author

@iSazonov doh... corrected.

@TravisEz13

Copy link
Copy Markdown
Member

I agree with @iSazonov . The tests in the issue look like a good starting point.

@TravisEz13 TravisEz13 added the WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module label Aug 5, 2017
@markekraus

Copy link
Copy Markdown
Contributor Author

@TravisEz13 Thanks. I added the 2 test that make sense. The other tests from the issue won't ever work unless CoreFX drastically changes their approach in System.Net.Http.HttpResponseMessage.

@markekraus markekraus force-pushed the GetRawContentHeader branch from 73d19ed to 823dd03 Compare August 7, 2017 23:18
@markekraus

Copy link
Copy Markdown
Contributor Author

@TravisEz13 @SteveL-MSFT Rebased PR on master to add test fixes from #4512. The new tests are passing. Let me know if I need to make any other changes.

};

foreach (var entry in response.Headers)
foreach(var headerCollection in headerCollections)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor point, insert a space after 'foreach' here and 'if' below to match the rest of the code.

@markekraus markekraus Aug 17, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dantraMSFT corrected.

{
headers[entry.Key] = entry.Value;
}
if(BaseResponse.Content != null){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor note: place '{' on a new line.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dantraMSFT corrected, along with space between if and (.

#endregion charset encoding tests

It "Verifies Invoke-WebRequest includes Content headers in Headers property" {
$command = "Invoke-WebRequest -Uri 'http://httpbin.org/get'"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use HTTPListener here instead of http://httpbin.org/get.
The tests under Context "BasicHtmlWebResponseObject Encoding tests" illustrate using 'test=response&output=$otuput' to pass HTML you want to get in the response. You should consider extending httplistener's 'response' option to allow additional options, such as specifying a content-type header value or other headers to support your testing. let me know if you need any help with it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dantraMSFT Thanks. I will work on this and submit more and better tests with your suggestions.


#endregion charset encoding tests

It "Verifies Invoke-WebRequest includes Content headers in Headers property" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these two tests need to be either be extended or additional tests added.
1: I don't believe verifying the presence of the header is sufficient; I believe the test should verify the value(s) as well.
2: You added logic to support headers with multiple values so you need to test that case.

@markekraus

Copy link
Copy Markdown
Contributor Author

@dantraMSFT I have added the requested test changes and httplistener now supports a headers option with a JSON object containing response header name/value pairs on the response test.

$statusCode = $queryItems["statuscode"]
$contentType = $queryItems["contenttype"]
$output = $queryItems["output"]
if ($queryItems['headers'])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be helpful to add a comment here that illustrates how the 'headers' value should be formatted; especially since this is the only documentation we have for the listener. :)
At a minimum, show the json structure. Even better would be to show a code sample similar to what you used in your tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dantraMSFT added. comments with examples

@TravisEz13

Copy link
Copy Markdown
Member

LGTM

@adityapatwardhan

Copy link
Copy Markdown
Member

@markekraus Can you trigger of feature tests? They seems to have failed last time on Travis CI.

@markekraus markekraus force-pushed the GetRawContentHeader branch from 42f5aca to 07d7b3d Compare August 18, 2017 20:58
@markekraus

Copy link
Copy Markdown
Contributor Author

@adityapatwardhan feature tag added.

@markekraus

Copy link
Copy Markdown
Contributor Author

@adityapatwardhan all tests passed this time. (last time an unrelated test hung accessing a 3rd party website).

@iSazonov

Copy link
Copy Markdown
Collaborator

LGTM.

Thanks for great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.