|
|
|
@ -105,14 +105,12 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
|
|
|
|
return client;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private WebRequest GetMonoRequest(HttpRequestOptions options, string method, bool enableHttpCompression)
|
|
|
|
|
private PropertyInfo _httpBehaviorPropertyInfo;
|
|
|
|
|
private WebRequest GetRequest(HttpRequestOptions options, string method, bool enableHttpCompression)
|
|
|
|
|
{
|
|
|
|
|
var request = (HttpWebRequest)WebRequest.Create(options.Url);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(options.AcceptHeader))
|
|
|
|
|
{
|
|
|
|
|
request.Accept = options.AcceptHeader;
|
|
|
|
|
}
|
|
|
|
|
AddRequestHeaders(request, options);
|
|
|
|
|
|
|
|
|
|
request.AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None;
|
|
|
|
|
|
|
|
|
@ -126,55 +124,37 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
|
|
|
|
request.Pipelined = true;
|
|
|
|
|
request.Timeout = 20000;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(options.UserAgent))
|
|
|
|
|
#if !__MonoCS__
|
|
|
|
|
// This is a hack to prevent KeepAlive from getting disabled internally by the HttpWebRequest
|
|
|
|
|
// May need to remove this for mono
|
|
|
|
|
var sp = request.ServicePoint;
|
|
|
|
|
if (_httpBehaviorPropertyInfo == null)
|
|
|
|
|
{
|
|
|
|
|
request.UserAgent = options.UserAgent;
|
|
|
|
|
_httpBehaviorPropertyInfo = sp.GetType().GetProperty("HttpBehaviour", BindingFlags.Instance | BindingFlags.NonPublic);
|
|
|
|
|
}
|
|
|
|
|
_httpBehaviorPropertyInfo.SetValue(sp, (byte)0, null);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return request;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private PropertyInfo _httpBehaviorPropertyInfo;
|
|
|
|
|
private WebRequest GetRequest(HttpRequestOptions options, string method, bool enableHttpCompression)
|
|
|
|
|
private void AddRequestHeaders(HttpWebRequest request, HttpRequestOptions options)
|
|
|
|
|
{
|
|
|
|
|
#if __MonoCS__
|
|
|
|
|
return GetMonoRequest(options, method, enableHttpCompression);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
var request = HttpWebRequest.CreateHttp(options.Url);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(options.AcceptHeader))
|
|
|
|
|
foreach (var header in options.RequestHeaders.ToList())
|
|
|
|
|
{
|
|
|
|
|
request.Accept = options.AcceptHeader;
|
|
|
|
|
if (string.Equals(header.Key, "Accept", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
request.Accept = header.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request.AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None;
|
|
|
|
|
|
|
|
|
|
request.CachePolicy = options.CachePolicy == Net.HttpRequestCachePolicy.None ?
|
|
|
|
|
new RequestCachePolicy(RequestCacheLevel.BypassCache) :
|
|
|
|
|
new RequestCachePolicy(RequestCacheLevel.Revalidate);
|
|
|
|
|
|
|
|
|
|
request.ConnectionGroupName = GetHostFromUrl(options.Url);
|
|
|
|
|
request.KeepAlive = true;
|
|
|
|
|
request.Method = method;
|
|
|
|
|
request.Pipelined = true;
|
|
|
|
|
request.Timeout = 20000;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(options.UserAgent))
|
|
|
|
|
else if (string.Equals(header.Key, "User-Agent", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
request.UserAgent = options.UserAgent;
|
|
|
|
|
request.UserAgent = header.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This is a hack to prevent KeepAlive from getting disabled internally by the HttpWebRequest
|
|
|
|
|
// May need to remove this for mono
|
|
|
|
|
var sp = request.ServicePoint;
|
|
|
|
|
if (_httpBehaviorPropertyInfo == null)
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_httpBehaviorPropertyInfo = sp.GetType().GetProperty("HttpBehaviour", BindingFlags.Instance | BindingFlags.NonPublic);
|
|
|
|
|
request.Headers.Set(header.Key, header.Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_httpBehaviorPropertyInfo.SetValue(sp, (byte)0, null);
|
|
|
|
|
|
|
|
|
|
return request;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|