[Foundation] Add support to ignore the cookies in the NSUrlSessionHandler.#7677
Conversation
…dler. This change allows to ignore the use of cookies and cookie containers in the NSUrlSessionHandler. There are two different cookie containers to consider: 1. The native NSHttoCookieStorage. 2. The managed CookieContainer. If the native one is set to null, the native code will not use a cookie storage, which is used as a flag to ignore the managed one. There is an interesting situation, we allow different types of sessions. From the cookie storage point of view, Default and Background sessions are the same, but Ephemeral is not, since we only want to store in ram the cookies and do not share them. This supposes a problem because Apple does not provide any API that will allow to determine the session type use in the configuration. The workaround has been to hide the direct native call for the configuration and add an enum value that can later be accessed in the NSUrlSessionHandler. Of course things cannot be that easy. When a session is created with the configuration, it creates a copy, and the internal session configuration does not longer have the flag, therefore, we need to store the session type in the handler. Fixes: dotnet#7659
chamons
left a comment
There was a problem hiding this comment.
I am not qualified to say if the PR is good or not, but some comments to fix until someone else can.
| public SessionConfigurationType SessiontType { | ||
| get => configurationType; | ||
| private set => configurationType = value; | ||
| } |
There was a problem hiding this comment.
I believe this is the same as:
public SessionConfigurationType SessiontType { get; private set; } = SessionConfigurationType.Default;There was a problem hiding this comment.
My point is that is a lot shorter :)
Co-Authored-By: Chris Hamons <chris.hamons@xamarin.com>
|
Build failure ✅ Build succeeded |
|
Build failure Test results2 tests failed, 85 tests passed.Failed tests
|
|
Build success |
| public void TestNSUrlSessionEphemeralDisabledCookies () | ||
| { | ||
| // assert we do throw an exception with ephemeral configs. | ||
| var config = NSUrlSessionConfiguration.EphemeralSessionConfiguration; |
| #if XAMCORE_2_0 | ||
| using Foundation; | ||
| #else | ||
| using MonoTouch.Foundation; |
There was a problem hiding this comment.
You don't need the !XAMCORE_2_0 code, we never build in that mode anymore.
…cios into ignore-cookies
|
Build failure Test results16 tests failed, 71 tests passed.Failed tests
|
|
Build failure Test results1 tests failed, 86 tests passed.Failed tests
|
|
Known issue: https://github.com/xamarin/maccore/issues/581 |
This change allows to ignore the use of cookies and cookie containers in
the NSUrlSessionHandler. There are two different cookie containers to
consider:
If the native one is set to null, the native code will not use a cookie
storage, which is used as a flag to ignore the managed one.
There is an interesting situation, we allow different types of sessions.
From the cookie storage point of view, Default and Background sessions
are the same, but Ephemeral is not, since we only want to store in ram
the cookies and do not share them.
This supposes a problem because Apple does not provide any API that will
allow to determine the session type use in the configuration. The
workaround has been to hide the direct native call for the configuration
and add an enum value that can later be accessed in the
NSUrlSessionHandler. Of course things cannot be that easy. When a
session is created with the configuration, it creates a copy, and the
internal session configuration does not longer have the flag, therefore,
we need to store the session type in the handler.
Fixes: #7659