Permalink
Browse files

Dispose HTTP request/response.

  • Loading branch information...
ejball committed Mar 23, 2017
1 parent ddbca5f commit c151d4cb397c3667c8741fa89f0c737e29914042
Showing with 7 additions and 5 deletions.
  1. +1 −1 SolutionInfo.cs
  2. +6 −4 src/Facility.Core/Http/HttpClientService.cs
View
@@ -1,6 +1,6 @@
using System.Reflection;
-[assembly: AssemblyVersion("1.2.0.0")]
+[assembly: AssemblyVersion("1.2.1.0")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCopyright("Copyright 2016-2017 Ed Ball")]
[assembly: AssemblyTrademark("")]
@@ -58,16 +58,16 @@ protected HttpClientService(HttpClientServiceSettings settings, Uri defaultBaseU
var httpRequestResult = TryCreateHttpRequest(mapping.HttpMethod, mapping.Path, mapping.GetUriParameters(request), mapping.GetRequestHeaders(request));
if (httpRequestResult.IsFailure)
return httpRequestResult.AsFailure();
- var httpRequest = httpRequestResult.Value;
-
+ using (var httpRequest = httpRequestResult.Value)
+ {
// create the request body if necessary
var requestBody = mapping.GetRequestBody(request);
if (requestBody != null)
httpRequest.Content = ContentSerializer.CreateHttpContent(requestBody);
// send the HTTP request and get the HTTP response
- var httpResponse = await SendRequestAsync(httpRequest, request, cancellationToken).ConfigureAwait(false);
-
+ using (var httpResponse = await SendRequestAsync(httpRequest, request, cancellationToken).ConfigureAwait(false))
+ {
// find the response mapping for the status code
var statusCode = httpResponse.StatusCode;
var responseMapping = mapping.ResponseMappings.FirstOrDefault(x => x.StatusCode == statusCode);
@@ -96,6 +96,8 @@ protected HttpClientService(HttpClientServiceSettings settings, Uri defaultBaseU
response = mapping.SetResponseHeaders(response, HttpServiceUtility.CreateDictionaryFromHeaders(httpResponse.Headers));
return ServiceResult.Success(response);
}
+ }
+ }
catch (OperationCanceledException) when (!cancellationToken.IsCancellationRequested)
{
// HttpClient timeout

0 comments on commit c151d4c

Please sign in to comment.