diff options
author | Marek Safar <marek.safar@gmail.com> | 2013-07-13 19:58:56 +0400 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2013-07-15 16:19:37 +0400 |
commit | 588d52e20513b669f01370ff30c92bfaf8082042 (patch) | |
tree | 70a7b3b3f2bfaf1ac8f60d86eea6e573bb37fd63 /mcs | |
parent | a2ba6c39737535f338748641dffe22111cba902c (diff) |
Implement webrequest cancellation. Fixes #13200
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.cs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.cs b/mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.cs index 720fc6812a6..656911ee0e2 100644 --- a/mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.cs +++ b/mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.cs @@ -312,8 +312,22 @@ namespace System.Net.Http await request.Content.CopyToAsync (stream).ConfigureAwait (false); } - // FIXME: GetResponseAsync does not accept cancellationToken - var wresponse = (HttpWebResponse) await wrequest.GetResponseAsync ().ConfigureAwait (false); + HttpWebResponse wresponse = null; + using (cancellationToken.Register (l => ((HttpWebRequest) l).Abort (), wrequest)) { + try { + wresponse = (HttpWebResponse) await wrequest.GetResponseAsync ().ConfigureAwait (false); + } catch (WebException we) { + if (we.Status != WebExceptionStatus.RequestCanceled) + throw; + } + + if (cancellationToken.IsCancellationRequested) { + var cancelled = new TaskCompletionSource<HttpResponseMessage> (); + cancelled.SetCanceled (); + return await cancelled.Task; + } + } + return CreateResponseMessage (wresponse, request); } } |