Skip to content

Commit

Permalink
add disposeflag to internalperform
Browse files Browse the repository at this point in the history
  • Loading branch information
aspriddell committed Aug 2, 2020
1 parent 05484be commit 50bd93a
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions DragonFruit.Common.Data/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,15 @@ public virtual HttpResponseMessage Perform(ApiRequest requestData)
ValidateRequest(requestData);

// perform and return postProcess result
return InternalPerform(requestData.GetRequest(Serializer), response => response);
return InternalPerform(requestData.GetRequest(Serializer), response => response, false);
}

/// <summary>
/// Perform a pre-fabricated <see cref="HttpRequestMessage"/>
/// </summary>
public virtual HttpResponseMessage Perform(HttpRequestMessage request)
{
return InternalPerform(request, response => response);
return InternalPerform(request, response => response, false);
}

/// <summary>
Expand All @@ -259,15 +259,15 @@ public virtual T Perform<T>(ApiRequest requestData) where T : class
ValidateRequest(requestData);
var request = requestData.GetRequest(Serializer);

return InternalPerform(request, response => ValidateAndProcess<T>(response, request));
return InternalPerform(request, response => ValidateAndProcess<T>(response, request), true);
}

/// <summary>
/// Perform a pre-fabricated <see cref="HttpRequestMessage"/> and deserialize the result to the specified type
/// </summary>
public virtual T Perform<T>(HttpRequestMessage request) where T : class
{
return InternalPerform(request, response => ValidateAndProcess<T>(response, request));
return InternalPerform(request, response => ValidateAndProcess<T>(response, request), true);
}

/// <summary>
Expand Down Expand Up @@ -298,15 +298,15 @@ HttpResponseMessage CopyProcess(HttpResponseMessage response)
return response; //we're not using this so return anything...
}

_ = InternalPerform(requestData.GetRequest(Serializer), CopyProcess);
_ = InternalPerform(requestData.GetRequest(Serializer), CopyProcess, true);
}

/// <summary>
/// Internal procedure for performing a web-request
/// </summary>
/// <param name="request">The request to perform</param>
/// <param name="processResult"><see cref="Func{T,TResult}"/> to process the <see cref="HttpResponseMessage"/></param>
protected T InternalPerform<T>(HttpRequestMessage request, Func<HttpResponseMessage, T> processResult)
protected T InternalPerform<T>(HttpRequestMessage request, Func<HttpResponseMessage, T> processResult, bool disposeResponse)
{
//get client and request (disposables)
var client = GetClient();
Expand All @@ -329,8 +329,11 @@ protected T InternalPerform<T>(HttpRequestMessage request, Func<HttpResponseMess
Interlocked.Decrement(ref _currentRequests);

//dispose
response?.Result?.Dispose();
response?.Dispose();
if (disposeResponse)
{
response?.Result?.Dispose();
response?.Dispose();
}

request?.Dispose();
}
Expand Down

0 comments on commit 50bd93a

Please sign in to comment.