Dispose HttpRequestMessage and HttpResponseMessage objects when making a http call
@@ -253,7 +253,8 @@ private async Task<HttpResponseInfo> MakeHttpRequest(HttpRequestInfo requestInfo
this.OnSendingRemoteHttpRequest(eventArgs);
HttpMethod method = new HttpMethod(requestInfo.HttpMethod);
- HttpRequestMessage requestMessage = new HttpRequestMessage(method, requestInfo.FullUri);
+ using (HttpRequestMessage requestMessage = new HttpRequestMessage(method, requestInfo.FullUri))
+ {
if (requestInfo.HttpMethod == HttpCommandInfo.GetCommand)
{
CacheControlHeaderValue cacheControlHeader = new CacheControlHeaderValue();
@@ -275,13 +276,17 @@ private async Task<HttpResponseInfo> MakeHttpRequest(HttpRequestInfo requestInfo
requestMessage.Content.Headers.ContentType = contentTypeHeader;
}
- HttpResponseMessage responseMessage = await this.client.SendAsync(requestMessage);
+ using (HttpResponseMessage responseMessage = await this.client.SendAsync(requestMessage))
+ {
HttpResponseInfo httpResponseInfo = new HttpResponseInfo();
httpResponseInfo.Body = await responseMessage.Content.ReadAsStringAsync();
httpResponseInfo.ContentType = responseMessage.Content.Headers.ContentType.ToString();
httpResponseInfo.StatusCode = responseMessage.StatusCode;
+
return httpResponseInfo;
}
+ }
+ }
private Response CreateResponse(HttpResponseInfo responseInfo)
{
