Skip to content

Conversation

@mandel-macaque
Copy link
Contributor

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: #7659

…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
Copy link
Contributor

@chamons chamons left a comment

Choose a reason for hiding this comment

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

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;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is the same as:

		public SessionConfigurationType SessiontType { get; private set; } = SessionConfigurationType.Default;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is.

Copy link
Contributor

Choose a reason for hiding this comment

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

My point is that is a lot shorter :)

@monojenkins
Copy link
Collaborator

Build failure
Build failed or was aborted

Build succeeded
API Diff (from stable)
ℹ️ API Diff (from PR only) (please review changes)
ℹ️ Generator Diff (please review changes)

@monojenkins
Copy link
Collaborator

Build failure
Build succeeded
API Diff (from stable)
ℹ️ API Diff (from PR only) (please review changes)
ℹ️ Generator Diff (please review changes)
🔥 Test run failed 🔥

Test results

2 tests failed, 85 tests passed.

Failed tests

  • Xtro/Mac: Failed (Test run failed.)
  • monotouch-test/watchOS 32-bits - simulator/Debug: Crashed

@monojenkins
Copy link
Collaborator

Build success
Build succeeded
API Diff (from stable)
ℹ️ API Diff (from PR only) (please review changes)
ℹ️ Generator Diff (please review changes)
Test run succeeded

Copy link
Member

@dalexsoto dalexsoto left a comment

Choose a reason for hiding this comment

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

LGTM 👍

public void TestNSUrlSessionEphemeralDisabledCookies ()
{
// assert we do throw an exception with ephemeral configs.
var config = NSUrlSessionConfiguration.EphemeralSessionConfiguration;
Copy link
Contributor

Choose a reason for hiding this comment

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

using here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch

#if XAMCORE_2_0
using Foundation;
#else
using MonoTouch.Foundation;
Copy link
Member

Choose a reason for hiding this comment

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

You don't need the !XAMCORE_2_0 code, we never build in that mode anymore.

@monojenkins
Copy link
Collaborator

Build failure
Build succeeded
API Diff (from stable)
ℹ️ API Diff (from PR only) (please review changes)
ℹ️ Generator Diff (please review changes)
🔥 Test run failed 🔥

Test results

16 tests failed, 71 tests passed.

Failed tests

  • xammac tests/Mac Modern/Debug: BuildFailure
  • xammac tests/Mac Modern/Release: BuildFailure
  • xammac tests/Mac Modern/Release: BuildFailure
  • monotouch-test/iOS Unified 32-bits - simulator/Debug: BuildFailure
  • monotouch-test/iOS Unified 32-bits - simulator/Debug (LinkSdk): BuildFailure
  • monotouch-test/iOS Unified 32-bits - simulator/Debug (static registrar): BuildFailure
  • monotouch-test/iOS Unified 32-bits - simulator/Release (all optimizations): BuildFailure
  • monotouch-test/iOS Unified 64-bits - simulator/Debug: BuildFailure
  • monotouch-test/iOS Unified 64-bits - simulator/Debug (LinkSdk): BuildFailure
  • monotouch-test/iOS Unified 64-bits - simulator/Debug (static registrar): BuildFailure
  • monotouch-test/iOS Unified 64-bits - simulator/Release (all optimizations): BuildFailure
  • monotouch-test/tvOS - simulator/Debug: BuildFailure
  • monotouch-test/tvOS - simulator/Debug (LinkSdk): BuildFailure
  • monotouch-test/tvOS - simulator/Debug (static registrar): BuildFailure
  • monotouch-test/tvOS - simulator/Release (all optimizations): BuildFailure
  • monotouch-test/watchOS 32-bits - simulator/Debug: Crashed

@monojenkins
Copy link
Collaborator

Build failure
Build succeeded
API Diff (from stable)
ℹ️ API Diff (from PR only) (please review changes)
ℹ️ Generator Diff (please review changes)
🔥 Test run failed 🔥

Test results

1 tests failed, 86 tests passed.

Failed tests

  • monotouch-test/watchOS 32-bits - simulator/Debug: Crashed

@mandel-macaque
Copy link
Contributor Author

@mandel-macaque mandel-macaque merged commit ac8e52c into dotnet:master Jan 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Foundation] Allow to ignore the use of cookies in the NSUrlSessionHanlder

6 participants