Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

CurlHandler fix for cookie handling - #5080

Merged
davidsh merged 1 commit into
dotnet:masterfrom
kapilash:i4960
Dec 28, 2015
Merged

davidsh merged 1 commit into
dotnet:masterfrom
kapilash:i4960

Conversation

@kapilash

Copy link
Copy Markdown
Contributor

CurlHandler has been handling cookies only from the final HTTP response.
The cookies sent during the intermediate http responses (during 3XX redirection as well as interim 401, 407 responses) were getting ignored.

This fix ensures that the cookies from all the responses are handled.

@kapilash

Copy link
Copy Markdown
Contributor Author

cc @vijaykota @davidsh @stephentoub

This and #5001 together fix #4960

@kapilash

Copy link
Copy Markdown
Contributor Author

The OpenSUSE failure is unrelated:

22:49:37 === TEST EXECUTION SUMMARY ===
22:49:37    System.Reflection.TypeExtensions.Tests  Total: 599, Errors: 0, Failed: 0, Skipped: 0, Time: 1.480s
22:49:38             at System.Reflection.Metadata.Tests.StringUtilsTests.IsEqualAscii()
22:49:38 Finished:    System.Reflection.Metadata.Tests 
22:49:38 
22:49:38 === TEST EXECUTION SUMMARY ===
22:49:38    System.Reflection.Metadata.Tests  Total: 125, Errors: 0, Failed: 1, Skipped: 0, Time: 2.470s
22:49:38 
error: One or more tests failed while running tests from 'System.Reflection.Metadata.Tests'.  Exit code 1.

@vijaykota

Copy link
Copy Markdown
Contributor

LGTM

@davidsh

davidsh commented Dec 21, 2015

Copy link
Copy Markdown
Contributor

Test Innerloop OpenSUSE13.2 Debug Build and Test

@kapilash

Copy link
Copy Markdown
Contributor Author

Test Innerloop Debug Build and Test ( #5083 )

@kapilash

Copy link
Copy Markdown
Contributor Author

@dotnet-bot test this please

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.

Is state._requestMessage.RequestUri the original URI or the new redirected URI? I wasn't sure looking at this code.

But for this to be correct, the RequestUri still needs to be the original URI while processing the response cookies. After the response cookies are processed completely, then the RequestUri can be updated to the new redirected URI as given in the 3xx HTTP response.

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.

(sorry, missed this comment. I did get the email notification but I could not find the comment here till now. )

I see my mistake in the code. In WinHttpHandler, adding into CookieContainer happens before setting the url

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.

Sorry I didn't understand this, @kapilash. Didn't we discuss that this is the behavior we need ie. the cookie container should contain the target (new) url? You had mentioned that if we were to use the old url, on the second hop, a cookie would not be found for the new url and the test case would fail

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.

You had mentioned that if we were to use the old url, on the second hop, a cookie would not be found for the new url and the test case would fail

Yes, @vijaykota. You were right all along. I based my understanding on what was happening when the test case is running and my misreading of WinHttpHandler.

@kapilash

Copy link
Copy Markdown
Contributor Author

The failure seems to be related to #5082 . Request for re tests are still including the OpenSuse build and test. So trying to close and reopen and hope #5083 will come into play.

CurlHandler has been handling cookies only from the final HTTP response.
The cookies sent during the intermediate http responses (during 3XX
redirection as well as interim 401, 407 responses) were getting ignored.
This fix ensures that the cookies from all the responses are handled.
@davidsh

davidsh commented Dec 24, 2015

Copy link
Copy Markdown
Contributor

You had mentioned that if we were to use the old url, on the second hop, a cookie would not be found for the new url and the test case would fail

I don't understand the answer to my questions about the uri being used to add the response cookies to the container.

The original uri should be used at all times when adding HTTP response cookies (i.e. Set-Cookie headers) to the container. Regardless of whether it is a 3xx (redirection response) or a 401/407 (auth response), the original uri used for that request needs to be used when adding the cookies to the cookie container. In this case of the 3xx redirection response, the HttpRequestMessage.RequestUri should only be updated after the response cookies have been parsed and added to the container.

@kapilash

Copy link
Copy Markdown
Contributor Author

@dotnet-bot test this please

@kapilash

Copy link
Copy Markdown
Contributor Author

@davidsh,

Regardless of whether it is a 3xx (redirection response) or a 401/407 (auth response), the original uri used for that request needs to be used when adding the cookies to the cookie container. In this case of the 3xx redirection response, the HttpRequestMessage.RequestUri should only be updated after the response cookies have been parsed and added to the container.

Thanks @davidsh. The code has been updated to reflect this. The cookie container is updated based on the original target uri. HttpRequestMessage.RequestUri, however, is updated as soon as we get to know the location. This difference between CurlHandler and WinHttpHandler is because of the way the callbacks are invoked. But otherwise, both have identical behavior now.

@davidsh

davidsh commented Dec 28, 2015

Copy link
Copy Markdown
Contributor

LGTM

@davidsh davidsh added this to the 1.0.0-rc2 milestone Dec 28, 2015
davidsh added a commit that referenced this pull request Dec 28, 2015
CurlHandler fix for cookie handling
@davidsh
davidsh merged commit afe1001 into dotnet:master Dec 28, 2015
@kapilash
kapilash deleted the i4960 branch February 15, 2016 09:37
@karelz karelz added the os-linux Linux OS (any supported distro) label Mar 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Net os-linux Linux OS (any supported distro)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants