Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…ent.
  • Loading branch information...
commit 50ee2b9b6c05168473608742d42f2fc6ad03ac6b 1 parent 758b0d4
David Fowler davidfowl authored
18 SignalR.Client/Http/DefaultHttpClient.cs
View
@@ -17,8 +17,13 @@ public class DefaultHttpClient : IHttpClient
/// <returns>A <see cref="Task{IResponse}"/>.</returns>
public Task<IResponse> GetAsync(string url, Action<IRequest> prepareRequest)
{
- return HttpHelper.GetAsync(url, request => prepareRequest(new HttpWebRequestWrapper(request)))
- .Then(response => (IResponse)new HttpWebResponseWrapper(response));
+ IRequest req = null;
+ return HttpHelper.GetAsync(url, request =>
+ {
+ req = new HttpWebRequestWrapper(request);
+ prepareRequest(req);
+ }
+ ).Then(response => (IResponse)new HttpWebResponseWrapper(req, response));
}
/// <summary>
@@ -30,8 +35,13 @@ public Task<IResponse> GetAsync(string url, Action<IRequest> prepareRequest)
/// <returns>A <see cref="Task{IResponse}"/>.</returns>
public Task<IResponse> PostAsync(string url, Action<IRequest> prepareRequest, Dictionary<string, string> postData)
{
- return HttpHelper.PostAsync(url, request => prepareRequest(new HttpWebRequestWrapper(request)), postData)
- .Then(response => (IResponse)new HttpWebResponseWrapper(response));
+ IRequest req = null;
+ return HttpHelper.PostAsync(url, request =>
+ {
+ req = new HttpWebRequestWrapper(request);
+ prepareRequest(req);
+ },
+ postData).Then(response => (IResponse)new HttpWebResponseWrapper(req, response));
}
}
}
11 SignalR.Client/Http/HttpWebResponseWrapper.cs
View
@@ -6,10 +6,12 @@ namespace SignalR.Client.Http
{
public class HttpWebResponseWrapper : IResponse
{
+ private readonly IRequest _request;
private readonly HttpWebResponse _response;
- public HttpWebResponseWrapper(HttpWebResponse response)
+ public HttpWebResponseWrapper(IRequest request, HttpWebResponse response)
{
+ _request = request;
_response = response;
}
@@ -25,6 +27,13 @@ public Stream GetResponseStream()
public void Close()
{
+ if (_request != null)
+ {
+ // Always try to abort the request since close hangs if the connection is
+ // being held open
+ _request.Abort();
+ }
+
((IDisposable)_response).Dispose();
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.