Repository navigation
Fix WinHttpHandler response handling for manual cookie parsing - #5001
Conversation
|
@CIPop @stephentoub PTAL |
There was a problem hiding this comment.
cookieHeader = HttpKnownHeaderNames.Cookie + ": " + cookieValues; should be more efficient than string.Format and avoids having to redefine the Cookie constant.
There was a problem hiding this comment.
Fixed. I had forgotten about the Common/src/System/Net/HttpKnownHeaderNames.cs class.
There was a problem hiding this comment.
private const string CookieHeaderNameWithColon = HttpKnownHeaderNames.Cookie + ":";?
|
Test Innerloop OpenSUSE13.2 Debug Build and Test |
There was a problem hiding this comment.
This adds a lot of unnecessary strings. We should at least have a TODO item saying that we need to split it into partial classes to ensure that only the needed strings are added to the binary.
There was a problem hiding this comment.
FWIW, the System.Net.Http.dll binary already drags in this class HttpKnownHeaderNames.cs. Now this change will drag in another copy for the System.Net.Http.WinHttpHandler.dll as well.
But won't the compiler assist in this in some way by figuring out what is really needed and trim out the rest?
There was a problem hiding this comment.
FYI, in #3199 I extended HttpKnownHeaderNames to allow looking up and reusing the header string instances to avoid having to always allocate new strings for known response headers. Not sure how easy it will be to split apart the strings with that optimization -- maybe splitting it up between request vs. response headers at some point.
There was a problem hiding this comment.
Although we're using a little more static storage in the library, doing too much micro-optimization on these allocations might end up making this code much harder to maintain and extend in the future. So, we should balance that against all of these optimizations (which we don't really understand the true quantitative benefits of).
There was a problem hiding this comment.
So, we should balance that against all of these optimizations (which we don't really understand the true quantitative benefits of).
What is the DLL size before and after this change?
My proposal was to simply create HttpKnownHeaderNames.Cookie.cs and HttpKnownHeaderNames.cs as partial and import within each project only what is needed. The split will be made whenever it's necessary to reduce the DLL size.
There was a problem hiding this comment.
I think for now, I'm going to undo the inclusion of HttpKnownHeaderNames.cs from this PR and simply use "Cookie" string directly.
I'll let the next PR such as #3199 look into further optimizations.
|
Test Innerloop Windows_NT Release Build and Test |
|
LGTM The object model needs improvement. |
|
Added comments and issue #5036 to track the WinHttp callback flags improvements. |
WinHttpHandler was losing 'Set-Cookie' response headers during auto redirection handling when the handler was in 'manual cookie' mode. I.e. `CookieUsePolicy.UseSpecifiedCookieContainer`. This is the only mode that HttpClientHandler uses. The 'Set-Cookie' headers were currently only parsed out when a final HTTP response happened. This meant that 'Set-Cookie' headers present in interim 3xx redirection responses as well as interim 401, 407 auth responses would not be stored into the CookieContainer. Hence, those same cookies could not be sent back to the server when needed. The fix is to make sure we parse out the 'Set-Cookie' headers whenever we get an HTTP response back from WinHTTP. As part of this fix, I re-factored out the cookie handling code into a separate class. I also added specific WinHttpHandler tests for the two different cookie modes as well as a HttpClientHandler test to validate cross-platform (i.e. CurlHandler). Address #4960 but further fixes are needed for *NIX as well.
|
Test Innerloop Ubuntu Release Build and Test |
Fix WinHttpHandler response handling for manual cookie parsing
WinHttpHandler was losing 'Set-Cookie' response headers during auto redirection handling when the handler was in 'manual cookie' mode. I.e.
CookieUsePolicy.UseSpecifiedCookieContainer. This is the only mode that HttpClientHandler uses.The 'Set-Cookie' headers were currently only parsed out when a final HTTP response happened. This meant that 'Set-Cookie' headers present in interim 3xx redirection responses as well as interim 401, 407 auth responses would not be stored into the CookieContainer. Hence, those same cookies could not be sent back to the server when needed.
The fix is to make sure we parse out the 'Set-Cookie' headers whenever we get an HTTP response back from WinHTTP. As part of this fix, I re-factored out the cookie handling code into a separate class. I also added specific WinHttpHandler tests for the two different cookie modes as well as a HttpClientHandler test to validate cross-platform (i.e. CurlHandler).
Fixes #4960