Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Fix fragment handling in HttpClient #27360

Merged
merged 2 commits into from
Feb 22, 2018
Merged

Conversation

stephentoub
Copy link
Member

SocketsHttpHandler isn't sending fragments, nor is it properly inheriting the fragment from the original request URI into the redirect location URI when the original URI had one and the redirect URI did not, even though RFC 7231 says it must. This commit fixes that for SocketsHttpHandler.

WinHttpHandler also isn't handling this inheritance according to the RFC. It appears that the logic for WinHttpHandler would actually need to be changed in WINHTTP itself, or else WinHttpHandler would need to be changed to do the redirects itself.

Neither CurlHandler or NetFxHandler send fragments at all.

This commit also fixes the test to correctly compare the expected and actual Uris... apparently Uri equality doesn't factor in fragments, so they're first converted to strings. It also updates the test to also validate that the server received the URI with the fragment included.

Closes https://github.com/dotnet/corefx/issues/27305
cc: @geoffkizer, @davidsh, @wfurt, @rmkerr

SocketsHttpHandler isn't sending fragments, nor is it properly inheriting the fragment from the original request URI into the redirect location URI when the original URI had one and the redirect URI did not, even though RFC 7231 says it must.  This commit fixes that for SocketsHttpHandler.

WinHttpHandler also isn't handling this inheritance according to the RFC. It appears that the logic for WinHttpHandler would actually need to be changed in WINHTTP itself, or else WinHttpHandler would need to be changed to do the redirects itself.

Neither CurlHandler or NetFxHandler send fragments at all.

This commit also fixes the test to correctly compare the expected and actual Uris... apparently Uri equality doesn't factor in fragments, so they're first converted to strings.  It also updates the test to also validate that the server received the URI with the fragment included.
Assert.NotEmpty(secondRequest.Result);
string[] statusLineParts = secondRequest.Result[0].Split(' ');
Assert.Equal(3, statusLineParts.Length);
Assert.Equal(expectedUrl.GetComponents(UriComponents.PathAndQuery | UriComponents.Fragment, UriFormat.SafeUnescaped), statusLineParts[1]);

Choose a reason for hiding this comment

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

Nit: shouldn't matter for this test, but shouldn't this technically use UriFormat.Escaped?

Copy link

@geoffkizer geoffkizer Feb 22, 2018

Choose a reason for hiding this comment

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

LGTM

@geoffkizer
Copy link

LGTM, one minor nit above

@stephentoub
Copy link
Member Author

@davidsh, why did you remove the System.Net.Http label? This applies to all handlers. There's a fix in SocketsHttpHandler, but the test is for all of them, and the others all suffer from the same or similar issues.

Copy link
Contributor

@rmkerr rmkerr left a comment

Choose a reason for hiding this comment

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

LGTM. That was quick!

@stephentoub
Copy link
Member Author

@dotnet-bot test Outerloop Windows x64 Debug Build please
@dotnet-bot test Windows x86 Release Build please (https://github.com/dotnet/corefx/issues/27363)

Copy link
Member

@wfurt wfurt left a comment

Choose a reason for hiding this comment

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

looks good.

@davidsh
Copy link
Contributor

davidsh commented Feb 22, 2018

@davidsh, why did you remove the System.Net.Http label? This applies to all handlers. There's a fix in SocketsHttpHandler, but the test is for all of them, and the others all suffer from the same or similar issues.

I based the label on where the produce code changes were made primarily which was SocketsHttpHandler. Doing this helps group all the PRs related to changes in SocketNetHttpHandler.

I don't have a strong opinion on this, so if you want, the label can be changed to just the generic "Http" label.

Apparently it sometimes doesn't do the "right thing" even in other cases.
@stephentoub
Copy link
Member Author

@dotnet-bot test Outerloop Windows x64 Debug Build please please

@stephentoub stephentoub merged commit a273be6 into dotnet:master Feb 22, 2018
@stephentoub stephentoub deleted the fixfragments branch February 22, 2018 19:25
@karelz karelz added this to the 2.1.0 milestone Mar 10, 2018
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Fix fragment handling in HttpClient

SocketsHttpHandler isn't sending fragments, nor is it properly inheriting the fragment from the original request URI into the redirect location URI when the original URI had one and the redirect URI did not, even though RFC 7231 says it must.  This commit fixes that for SocketsHttpHandler.

WinHttpHandler also isn't handling this inheritance according to the RFC. It appears that the logic for WinHttpHandler would actually need to be changed in WINHTTP itself, or else WinHttpHandler would need to be changed to do the redirects itself.

Neither CurlHandler or NetFxHandler send fragments at all.

This commit also fixes the test to correctly compare the expected and actual Uris... apparently Uri equality doesn't factor in fragments, so they're first converted to strings.  It also updates the test to also validate that the server received the URI with the fragment included.

* Disable the fragments test on WinHttpHandler

Apparently it sometimes doesn't do the "right thing" even in other cases.


Commit migrated from dotnet/corefx@a273be6
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Behavioral difference between Linux and Windows in httprequest with 302 reply and #
6 participants