Skip to content

Commit

Permalink
[Foundation] Ensure that post requests are not cached by the native
Browse files Browse the repository at this point in the history
code.

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.
  • Loading branch information
mandel-macaque committed Apr 12, 2022
1 parent b8eb1c3 commit 2f2df7d
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

0 comments on commit 2f2df7d

Please sign in to comment.