Skip to content

Commit

Permalink
[Foundation] Ensure that post requests are not cached by the native c…
Browse files Browse the repository at this point in the history
…ode. (#14739)

The behaviour from apple is wrong, PUT and POST are differnet in that PUT is idempotent.
Calling PUT several times successively has the same effect (that is no side effect),
where successive identical POST may have additional effects

We should not let the native code cache the calls.

Co-authored-by: Manuel de la Pena <[email protected]>
  • Loading branch information
1 parent 568bdb2 commit 43e060a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Foundation/NSUrlSessionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,13 @@ void SetResponse (InflightData inflight)
[Preserve (Conditional = true)]
public override void WillCacheResponse (NSUrlSession session, NSUrlSessionDataTask dataTask, NSCachedUrlResponse proposedResponse, Action<NSCachedUrlResponse> completionHandler)
{
completionHandler (sessionHandler.DisableCaching ? null! : proposedResponse);
var inflight = GetInflightData (dataTask);

if (inflight is null)
return;
// apple caches post request with a body, which should not happen. https://github.com/xamarin/maccore/issues/2571
var disableCache = sessionHandler.DisableCaching || (inflight.Request.Method == HttpMethod.Post && inflight.Request.Content is not null);
completionHandler (disableCache ? null! : proposedResponse);
}

[Preserve (Conditional = true)]
Expand Down

3 comments on commit 43e060a

@vs-mobiletools-engineering-service2
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

✅ Tests on macOS Mac Catalina (10.15) passed ✅

Tests passed

All tests on macOS Mac Catalina (10.15) passed.

Pipeline on Agent
[Foundation] Ensure that post requests are not cached by the native code. (#14739)

@vs-mobiletools-engineering-service2
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

✅ Tests on macOS M1 - Mac Big Sur (11.5) passed ✅

Tests passed

All tests on macOS M1 - Mac Big Sur (11.5) passed.

Pipeline on Agent
[Foundation] Ensure that post requests are not cached by the native code. (#14739)

@vs-mobiletools-engineering-service2
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

❌ [CI Build] Tests failed on VSTS: simulator tests iOS ❌

Tests failed on VSTS: simulator tests iOS.

Test results

5 tests failed, 229 tests passed.

Failed tests

  • monotouch-test/watchOS 32-bits - simulator/Debug: TimedOut
  • monotouch-test/watchOS 32-bits - simulator/Debug (LinkSdk): Crashed
  • monotouch-test/watchOS 32-bits - simulator/Debug (static registrar): Crashed
  • monotouch-test/watchOS 32-bits - simulator/Release (all optimizations): Crashed
  • monotouch-test/watchOS 32-bits - simulator/Debug (all optimizations): Crashed

Pipeline on Agent XAMBOT-1042.Monterey'
[Foundation] Ensure that post requests are not cached by the native code. (#14739)

Please sign in to comment.