runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Corefx HttpClientHandler CookieContainer property deviates from Desktop

Open kapilash opened this issue 11 years ago • 3 comments

During the PR for dotnet/corefx#3178 , it was discovered that the HttpClientHandler of corefx deviates from desktop .Net version w.r.t the setter for CookieContainer property. Setting a null value results in an exception in the desktop version. In case of corefx, it results in an error during SendAsync.

kapilash avatar Sep 12 '15 18:09 kapilash

This was discussed during the WinHttpHandler API review meeting. The reasoning here is that WinHttpHandler has an option for "internal/native cookie handling", in which case null is a valid value for CookieContainer (the native WinHTTP stack then manages cookies). On the other hand, desktop .NET framework has no cookie handling options other than using the managed cookie container.

The scenario where SendAsync throws in WinHttpHandler is when ((CookieUsePolicy == UseSpecifiedCookieContainer) && (CookieContainer == null)). And this cannot be checked in the setter, since developers could set the two properties in either order. Hence, the best place to check this was in the SendAsync method.

Hope this helps, Sid.

SidharthNabar avatar Sep 14 '15 16:09 SidharthNabar

Yes, I remember that meeting. However, we still could provide app-compat behavior in the HttpClientHandler layer by throwing ArgumentNullException if someone sets a NULL CookieContainer. In general, the NULL value doesn't hurt anything, per se, since the CookieContainer won't be used at all when the enum value for WinHttpHandler.CookieUsePolicy = UseInternalCookieStoreOnly. However, semantically, it has no use at least in so far as the HttpClientHandler layer itself.

So, the consistent thing to do in the HttpClientHandler layer (above the WinHttpHandler layer on Windows) is probably to be consistent and just throw the exception in the setter. This would keep the same behavior across all platforms for the setter of the HttpClientHandler.CookieContainer property.

davidsh avatar Sep 14 '15 16:09 davidsh

This sounds simple according to @davidsh:

So, the consistent thing to do in the HttpClientHandler layer (above the WinHttpHandler layer on Windows) is probably to be consistent and just throw the exception in the setter. This would keep the same behavior across all platforms for the setter of the HttpClientHandler.CookieContainer property.

We would also need a test that passes on .Net Framework and in .Net Core.

CIPop avatar Dec 09 '16 00:12 CIPop