aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-05-20 14:03:09 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-05-20 14:03:09 -0400
commitc11c8bfdb4c5a28c8218e3693021ac980c931321 (patch)
tree1fe91b36bea37581d624ec94db80c9a941701682 /MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
parent466d00b0214ba80421e53473b8cb5f38278adda1 (diff)
re-enable http compression for all providers except for last fm
Diffstat (limited to 'MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs')
-rw-r--r--MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs17
1 files changed, 10 insertions, 7 deletions
diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
index 074994619..c84239f92 100644
--- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
+++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
@@ -80,7 +80,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
/// <param name="host">The host.</param>
/// <returns>HttpClient.</returns>
/// <exception cref="System.ArgumentNullException">host</exception>
- private HttpClient GetHttpClient(string host)
+ private HttpClient GetHttpClient(string host, bool enableHttpCompression)
{
if (string.IsNullOrEmpty(host))
{
@@ -88,17 +88,20 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
}
HttpClient client;
- if (!_httpClients.TryGetValue(host, out client))
+
+ var key = host + enableHttpCompression;
+
+ if (!_httpClients.TryGetValue(key, out client))
{
var handler = new WebRequestHandler
{
CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache),
- AutomaticDecompression = DecompressionMethods.None
+ AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None
};
client = new HttpClient(handler);
client.Timeout = TimeSpan.FromSeconds(20);
- _httpClients.TryAdd(host, client);
+ _httpClients.TryAdd(key, client);
}
return client;
@@ -182,7 +185,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
{
options.CancellationToken.ThrowIfCancellationRequested();
- var response = await GetHttpClient(GetHostFromUrl(options.Url)).SendAsync(message, HttpCompletionOption.ResponseHeadersRead, options.CancellationToken).ConfigureAwait(false);
+ var response = await GetHttpClient(GetHostFromUrl(options.Url), options.EnableHttpCompression).SendAsync(message, HttpCompletionOption.ResponseHeadersRead, options.CancellationToken).ConfigureAwait(false);
if (options.EnableResponseCache)
{
@@ -411,7 +414,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
{
cancellationToken.ThrowIfCancellationRequested();
- var msg = await GetHttpClient(GetHostFromUrl(url)).PostAsync(url, content, cancellationToken).ConfigureAwait(false);
+ var msg = await GetHttpClient(GetHostFromUrl(url), false).PostAsync(url, content, cancellationToken).ConfigureAwait(false);
EnsureSuccessStatusCode(msg);
@@ -472,7 +475,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
using (var message = GetHttpRequestMessage(options))
{
- using (var response = await GetHttpClient(GetHostFromUrl(options.Url)).SendAsync(message, HttpCompletionOption.ResponseHeadersRead, options.CancellationToken).ConfigureAwait(false))
+ using (var response = await GetHttpClient(GetHostFromUrl(options.Url), options.EnableHttpCompression).SendAsync(message, HttpCompletionOption.ResponseHeadersRead, options.CancellationToken).ConfigureAwait(false))
{
EnsureSuccessStatusCode(response);