re-enable http compression for all providers except for last fm
This commit is contained in:
parent
466d00b021
commit
c11c8bfdb4
|
@ -80,7 +80,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
||||||
/// <param name="host">The host.</param>
|
/// <param name="host">The host.</param>
|
||||||
/// <returns>HttpClient.</returns>
|
/// <returns>HttpClient.</returns>
|
||||||
/// <exception cref="System.ArgumentNullException">host</exception>
|
/// <exception cref="System.ArgumentNullException">host</exception>
|
||||||
private HttpClient GetHttpClient(string host)
|
private HttpClient GetHttpClient(string host, bool enableHttpCompression)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(host))
|
if (string.IsNullOrEmpty(host))
|
||||||
{
|
{
|
||||||
|
@ -88,17 +88,20 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpClient client;
|
HttpClient client;
|
||||||
if (!_httpClients.TryGetValue(host, out client))
|
|
||||||
|
var key = host + enableHttpCompression;
|
||||||
|
|
||||||
|
if (!_httpClients.TryGetValue(key, out client))
|
||||||
{
|
{
|
||||||
var handler = new WebRequestHandler
|
var handler = new WebRequestHandler
|
||||||
{
|
{
|
||||||
CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache),
|
CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache),
|
||||||
AutomaticDecompression = DecompressionMethods.None
|
AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None
|
||||||
};
|
};
|
||||||
|
|
||||||
client = new HttpClient(handler);
|
client = new HttpClient(handler);
|
||||||
client.Timeout = TimeSpan.FromSeconds(20);
|
client.Timeout = TimeSpan.FromSeconds(20);
|
||||||
_httpClients.TryAdd(host, client);
|
_httpClients.TryAdd(key, client);
|
||||||
}
|
}
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
|
@ -182,7 +185,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
||||||
{
|
{
|
||||||
options.CancellationToken.ThrowIfCancellationRequested();
|
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)
|
if (options.EnableResponseCache)
|
||||||
{
|
{
|
||||||
|
@ -411,7 +414,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
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);
|
EnsureSuccessStatusCode(msg);
|
||||||
|
|
||||||
|
@ -472,7 +475,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
||||||
|
|
||||||
using (var message = GetHttpRequestMessage(options))
|
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);
|
EnsureSuccessStatusCode(response);
|
||||||
|
|
||||||
|
|
|
@ -49,5 +49,12 @@ namespace MediaBrowser.Common.Net
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value><c>true</c> if [enable response caching]; otherwise, <c>false</c>.</value>
|
/// <value><c>true</c> if [enable response caching]; otherwise, <c>false</c>.</value>
|
||||||
public bool EnableResponseCache { get; set; }
|
public bool EnableResponseCache { get; set; }
|
||||||
|
|
||||||
|
public bool EnableHttpCompression { get; set; }
|
||||||
|
|
||||||
|
public HttpRequestOptions()
|
||||||
|
{
|
||||||
|
EnableHttpCompression = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,8 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||||
Url = url,
|
Url = url,
|
||||||
ResourcePool = LastfmResourcePool,
|
ResourcePool = LastfmResourcePool,
|
||||||
CancellationToken = cancellationToken,
|
CancellationToken = cancellationToken,
|
||||||
EnableResponseCache = true
|
EnableResponseCache = true,
|
||||||
|
EnableHttpCompression = false
|
||||||
|
|
||||||
}).ConfigureAwait(false))
|
}).ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
|
|
|
@ -98,7 +98,8 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||||
Url = url,
|
Url = url,
|
||||||
ResourcePool = LastfmResourcePool,
|
ResourcePool = LastfmResourcePool,
|
||||||
CancellationToken = cancellationToken,
|
CancellationToken = cancellationToken,
|
||||||
EnableResponseCache = true
|
EnableResponseCache = true,
|
||||||
|
EnableHttpCompression = false
|
||||||
|
|
||||||
}).ConfigureAwait(false))
|
}).ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
|
@ -191,7 +192,8 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||||
Url = url,
|
Url = url,
|
||||||
ResourcePool = LastfmResourcePool,
|
ResourcePool = LastfmResourcePool,
|
||||||
CancellationToken = cancellationToken,
|
CancellationToken = cancellationToken,
|
||||||
EnableResponseCache = true
|
EnableResponseCache = true,
|
||||||
|
EnableHttpCompression = false
|
||||||
|
|
||||||
}).ConfigureAwait(false))
|
}).ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user