aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2017-10-20 12:16:56 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2017-10-20 12:16:56 -0400
commit060215143ff62e4cf475a493e57c8607beca8640 (patch)
tree1d1095525a83bb8183184db952d28556bc05f323 /MediaBrowser.Common
parent86226ff97c7d6dc4005c3bb1978861e948de1e20 (diff)
improve httpclient resource disposal
Diffstat (limited to 'MediaBrowser.Common')
-rw-r--r--MediaBrowser.Common/Net/IHttpClient.cs47
-rw-r--r--MediaBrowser.Common/Updates/GithubUpdater.cs26
2 files changed, 16 insertions, 57 deletions
diff --git a/MediaBrowser.Common/Net/IHttpClient.cs b/MediaBrowser.Common/Net/IHttpClient.cs
index 15257715f5..cf55119653 100644
--- a/MediaBrowser.Common/Net/IHttpClient.cs
+++ b/MediaBrowser.Common/Net/IHttpClient.cs
@@ -19,24 +19,6 @@ namespace MediaBrowser.Common.Net
Task<HttpResponseInfo> GetResponse(HttpRequestOptions options);
/// <summary>
- /// Performs a GET request and returns the resulting stream
- /// </summary>
- /// <param name="url">The URL.</param>
- /// <param name="resourcePool">The resource pool.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>Task{Stream}.</returns>
- /// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
- Task<Stream> Get(string url, SemaphoreSlim resourcePool, CancellationToken cancellationToken);
-
- /// <summary>
- /// Gets the specified URL.
- /// </summary>
- /// <param name="url">The URL.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>Task{Stream}.</returns>
- Task<Stream> Get(string url, CancellationToken cancellationToken);
-
- /// <summary>
/// Gets the specified options.
/// </summary>
/// <param name="options">The options.</param>
@@ -52,35 +34,6 @@ namespace MediaBrowser.Common.Net
Task<HttpResponseInfo> SendAsync(HttpRequestOptions options, string httpMethod);
/// <summary>
- /// Performs a POST request
- /// </summary>
- /// <param name="url">The URL.</param>
- /// <param name="postData">Params to add to the POST data.</param>
- /// <param name="resourcePool">The resource pool.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>stream on success, null on failure</returns>
- /// <exception cref="System.ArgumentNullException">postData</exception>
- /// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
- Task<Stream> Post(string url, Dictionary<string, string> postData, SemaphoreSlim resourcePool, CancellationToken cancellationToken);
-
- /// <summary>
- /// Posts the specified URL.
- /// </summary>
- /// <param name="url">The URL.</param>
- /// <param name="postData">The post data.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>Task{Stream}.</returns>
- Task<Stream> Post(string url, Dictionary<string, string> postData, CancellationToken cancellationToken);
-
- /// <summary>
- /// Posts the specified options with post data
- /// </summary>
- /// <param name="options">The options</param>
- /// <param name="postData">The post data</param>
- /// <returns>Task{Stream}</returns>
- Task<Stream> Post(HttpRequestOptions options, Dictionary<string, string> postData);
-
- /// <summary>
/// Posts the specified options.
/// </summary>
/// <param name="options">The options.</param>
diff --git a/MediaBrowser.Common/Updates/GithubUpdater.cs b/MediaBrowser.Common/Updates/GithubUpdater.cs
index 2106ac6d52..30abdc5da5 100644
--- a/MediaBrowser.Common/Updates/GithubUpdater.cs
+++ b/MediaBrowser.Common/Updates/GithubUpdater.cs
@@ -40,11 +40,14 @@ namespace MediaBrowser.Common.Updates
options.CacheLength = cacheLength;
}
- using (var stream = await _httpClient.Get(options).ConfigureAwait(false))
+ using (var response = await _httpClient.SendAsync(options, "GET").ConfigureAwait(false))
{
- var obj = _jsonSerializer.DeserializeFromStream<RootObject[]>(stream);
+ using (var stream = response.Content)
+ {
+ var obj = _jsonSerializer.DeserializeFromStream<RootObject[]>(stream);
- return CheckForUpdateResult(obj, minVersion, updateLevel, assetFilename, packageName, targetFilename);
+ return CheckForUpdateResult(obj, minVersion, updateLevel, assetFilename, packageName, targetFilename);
+ }
}
}
@@ -110,17 +113,20 @@ namespace MediaBrowser.Common.Updates
BufferContent = false
};
- using (var stream = await _httpClient.Get(options).ConfigureAwait(false))
+ using (var response = await _httpClient.SendAsync(options, "GET").ConfigureAwait(false))
{
- var obj = _jsonSerializer.DeserializeFromStream<RootObject[]>(stream);
+ using (var stream = response.Content)
+ {
+ var obj = _jsonSerializer.DeserializeFromStream<RootObject[]>(stream);
- obj = obj.Where(i => (i.assets ?? new List<Asset>()).Any(a => IsAsset(a, assetFilename, i.tag_name))).ToArray();
+ obj = obj.Where(i => (i.assets ?? new List<Asset>()).Any(a => IsAsset(a, assetFilename, i.tag_name))).ToArray();
- list.AddRange(obj.Where(i => MatchesUpdateLevel(i, PackageVersionClass.Release)).OrderByDescending(GetVersion).Take(1));
- list.AddRange(obj.Where(i => MatchesUpdateLevel(i, PackageVersionClass.Beta)).OrderByDescending(GetVersion).Take(1));
- list.AddRange(obj.Where(i => MatchesUpdateLevel(i, PackageVersionClass.Dev)).OrderByDescending(GetVersion).Take(1));
+ list.AddRange(obj.Where(i => MatchesUpdateLevel(i, PackageVersionClass.Release)).OrderByDescending(GetVersion).Take(1));
+ list.AddRange(obj.Where(i => MatchesUpdateLevel(i, PackageVersionClass.Beta)).OrderByDescending(GetVersion).Take(1));
+ list.AddRange(obj.Where(i => MatchesUpdateLevel(i, PackageVersionClass.Dev)).OrderByDescending(GetVersion).Take(1));
- return list;
+ return list;
+ }
}
}