Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/Foundation/NSUrlSessionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,24 @@ public override void DidReceiveResponse (NSUrlSession session, NSUrlSessionDataT
var inflight = GetInflightData (dataTask);

try {
// ensure that we did not cancel the request, if we did, do cancel the task
if (inflight.CancellationToken.IsCancellationRequested) {
dataTask.Cancel ();
}

var urlResponse = (NSHttpUrlResponse)response;
var status = (int)urlResponse.StatusCode;

var content = new NSUrlSessionDataTaskStreamContent (inflight.Stream, () => {
if (!inflight.Completed) {
dataTask.Cancel ();
}

inflight.Disposed = true;
inflight.Stream.TrySetException (new ObjectDisposedException ("The content stream was disposed."));

sessionHandler.RemoveInflightData (dataTask);
});
}, inflight.CancellationToken);

// NB: The double cast is because of a Xamarin compiler bug
var httpResponse = new HttpResponseMessage ((HttpStatusCode)status) {
Expand Down Expand Up @@ -278,7 +287,7 @@ public override void DidCompleteWithError (NSUrlSession session, NSUrlSessionTas
{
var inflight = GetInflightData (task);

// this can happen if the HTTP request times out and it is removed as part of the cancelation process
// this can happen if the HTTP request times out and it is removed as part of the cancellation process
if (inflight != null) {
// set the stream as finished
inflight.Stream.TrySetReceivedAllData ();
Expand Down Expand Up @@ -396,7 +405,7 @@ class NSUrlSessionDataTaskStreamContent : StreamContent
{
Action disposed;

public NSUrlSessionDataTaskStreamContent (NSUrlSessionDataTaskStream source, Action onDisposed) : base (source)
public NSUrlSessionDataTaskStreamContent (NSUrlSessionDataTaskStream source, Action onDisposed, CancellationToken token) : base (source, token)
{
disposed = onDisposed;
}
Expand Down