[Foundation] Ensure that post requests are not cached by the native code.(#14729)

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.
This commit is contained in:
Manuel de la Pena 2022-04-13 14:09:10 -04:00 коммит произвёл GitHub
Родитель 4c8d4457e5
Коммит 1f1189fae0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 7 добавлений и 1 удалений

Просмотреть файл

@ -857,7 +857,13 @@ namespace Foundation {
[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)]