Skip to content
This repository
Browse code

Abort the request before calling close on the request in the .NET cli…

…ent.
  • Loading branch information...
commit 50ee2b9b6c05168473608742d42f2fc6ad03ac6b 1 parent 758b0d4
David Fowler authored July 21, 2012
18  SignalR.Client/Http/DefaultHttpClient.cs
@@ -17,8 +17,13 @@ public class DefaultHttpClient : IHttpClient
17 17
         /// <returns>A <see cref="Task{IResponse}"/>.</returns>
18 18
         public Task<IResponse> GetAsync(string url, Action<IRequest> prepareRequest)
19 19
         {
20  
-            return HttpHelper.GetAsync(url, request => prepareRequest(new HttpWebRequestWrapper(request)))
21  
-                             .Then(response => (IResponse)new HttpWebResponseWrapper(response));
  20
+            IRequest req = null;
  21
+            return HttpHelper.GetAsync(url, request =>
  22
+            {
  23
+                req = new HttpWebRequestWrapper(request);
  24
+                prepareRequest(req);
  25
+            }
  26
+            ).Then(response => (IResponse)new HttpWebResponseWrapper(req, response));
22 27
         }
23 28
 
24 29
         /// <summary>
@@ -30,8 +35,13 @@ public Task<IResponse> GetAsync(string url, Action<IRequest> prepareRequest)
30 35
         /// <returns>A <see cref="Task{IResponse}"/>.</returns>
31 36
         public Task<IResponse> PostAsync(string url, Action<IRequest> prepareRequest, Dictionary<string, string> postData)
32 37
         {
33  
-            return HttpHelper.PostAsync(url, request => prepareRequest(new HttpWebRequestWrapper(request)), postData)
34  
-                             .Then(response => (IResponse)new HttpWebResponseWrapper(response));
  38
+            IRequest req = null;
  39
+            return HttpHelper.PostAsync(url, request =>
  40
+            {
  41
+                req = new HttpWebRequestWrapper(request);
  42
+                prepareRequest(req);
  43
+            },
  44
+            postData).Then(response => (IResponse)new HttpWebResponseWrapper(req, response));
35 45
         }
36 46
     }
37 47
 }
11  SignalR.Client/Http/HttpWebResponseWrapper.cs
@@ -6,10 +6,12 @@ namespace SignalR.Client.Http
6 6
 {
7 7
     public class HttpWebResponseWrapper : IResponse
8 8
     {
  9
+        private readonly IRequest _request;
9 10
         private readonly HttpWebResponse _response;
10 11
 
11  
-        public HttpWebResponseWrapper(HttpWebResponse response)
  12
+        public HttpWebResponseWrapper(IRequest request, HttpWebResponse response)
12 13
         {
  14
+            _request = request;
13 15
             _response = response;
14 16
         }
15 17
 
@@ -25,6 +27,13 @@ public Stream GetResponseStream()
25 27
 
26 28
         public void Close()
27 29
         {
  30
+            if (_request != null)
  31
+            {
  32
+                // Always try to abort the request since close hangs if the connection is 
  33
+                // being held open
  34
+                _request.Abort();
  35
+            }
  36
+
28 37
             ((IDisposable)_response).Dispose();
29 38
         }
30 39
     }

0 notes on commit 50ee2b9

Please sign in to comment.
Something went wrong with that request. Please try again.