Fixed: uTorrent api proxy would fail on specific Win10 configurations. (The Phoenix Rises)
Moved token queryparam to start since uTorrent requires it. Fixed handling response missing an expected Set-Cookie header. Force Cache-Control: no-cache for uTorrent. Added Connection: KeepAlive to fix inexplicable uTorrent api failure.
This commit is contained in:
parent
edea488dbe
commit
e1ea17cabf
|
@ -17,7 +17,7 @@ namespace NzbDrone.Common.Http.Dispatchers
|
||||||
|
|
||||||
webRequest.Method = request.Method.ToString();
|
webRequest.Method = request.Method.ToString();
|
||||||
webRequest.UserAgent = UserAgentBuilder.UserAgent;
|
webRequest.UserAgent = UserAgentBuilder.UserAgent;
|
||||||
webRequest.KeepAlive = false;
|
webRequest.KeepAlive = request.ConnectionKeepAlive;
|
||||||
webRequest.AllowAutoRedirect = request.AllowAutoRedirect;
|
webRequest.AllowAutoRedirect = request.AllowAutoRedirect;
|
||||||
webRequest.CookieContainer = cookies;
|
webRequest.CookieContainer = cookies;
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ namespace NzbDrone.Common.Http
|
||||||
public string ContentSummary { get; set; }
|
public string ContentSummary { get; set; }
|
||||||
public bool SuppressHttpError { get; set; }
|
public bool SuppressHttpError { get; set; }
|
||||||
public bool AllowAutoRedirect { get; set; }
|
public bool AllowAutoRedirect { get; set; }
|
||||||
|
public bool ConnectionKeepAlive { get; set; }
|
||||||
public Dictionary<string, string> Cookies { get; private set; }
|
public Dictionary<string, string> Cookies { get; private set; }
|
||||||
public bool StoreResponseCookie { get; set; }
|
public bool StoreResponseCookie { get; set; }
|
||||||
public TimeSpan RequestTimeout { get; set; }
|
public TimeSpan RequestTimeout { get; set; }
|
||||||
|
|
|
@ -20,6 +20,7 @@ namespace NzbDrone.Common.Http
|
||||||
public HttpHeader Headers { get; private set; }
|
public HttpHeader Headers { get; private set; }
|
||||||
public bool SuppressHttpError { get; set; }
|
public bool SuppressHttpError { get; set; }
|
||||||
public bool AllowAutoRedirect { get; set; }
|
public bool AllowAutoRedirect { get; set; }
|
||||||
|
public bool ConnectionKeepAlive { get; set; }
|
||||||
public NetworkCredential NetworkCredential { get; set; }
|
public NetworkCredential NetworkCredential { get; set; }
|
||||||
public Dictionary<string, string> Cookies { get; private set; }
|
public Dictionary<string, string> Cookies { get; private set; }
|
||||||
public List<HttpFormData> FormData { get; private set; }
|
public List<HttpFormData> FormData { get; private set; }
|
||||||
|
@ -98,6 +99,7 @@ namespace NzbDrone.Common.Http
|
||||||
request.Method = Method;
|
request.Method = Method;
|
||||||
request.SuppressHttpError = SuppressHttpError;
|
request.SuppressHttpError = SuppressHttpError;
|
||||||
request.AllowAutoRedirect = AllowAutoRedirect;
|
request.AllowAutoRedirect = AllowAutoRedirect;
|
||||||
|
request.ConnectionKeepAlive = ConnectionKeepAlive;
|
||||||
|
|
||||||
if (NetworkCredential != null)
|
if (NetworkCredential != null)
|
||||||
{
|
{
|
||||||
|
@ -232,6 +234,13 @@ namespace NzbDrone.Common.Http
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual HttpRequestBuilder KeepAlive(bool keepAlive = true)
|
||||||
|
{
|
||||||
|
ConnectionKeepAlive = keepAlive;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public virtual HttpRequestBuilder Post()
|
public virtual HttpRequestBuilder Post()
|
||||||
{
|
{
|
||||||
Method = HttpMethod.POST;
|
Method = HttpMethod.POST;
|
||||||
|
@ -253,6 +262,19 @@ namespace NzbDrone.Common.Http
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual HttpRequestBuilder AddPrefixQueryParam(string key, object value, bool replace = false)
|
||||||
|
{
|
||||||
|
if (replace)
|
||||||
|
{
|
||||||
|
QueryParams.RemoveAll(v => v.Key == key);
|
||||||
|
SuffixQueryParams.RemoveAll(v => v.Key == key);
|
||||||
|
}
|
||||||
|
|
||||||
|
QueryParams.Insert(0, new KeyValuePair<string, string>(key, value.ToString()));
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public virtual HttpRequestBuilder AddQueryParam(string key, object value, bool replace = false)
|
public virtual HttpRequestBuilder AddQueryParam(string key, object value, bool replace = false)
|
||||||
{
|
{
|
||||||
if (replace)
|
if (replace)
|
||||||
|
|
|
@ -61,12 +61,16 @@ namespace NzbDrone.Common.Http
|
||||||
{
|
{
|
||||||
var result = new Dictionary<string, string>();
|
var result = new Dictionary<string, string>();
|
||||||
|
|
||||||
foreach (var cookie in Headers.GetValues("Set-Cookie"))
|
var setCookieHeaders = Headers.GetValues("Set-Cookie");
|
||||||
|
if (setCookieHeaders != null)
|
||||||
{
|
{
|
||||||
var match = RegexSetCookie.Match(cookie);
|
foreach (var cookie in setCookieHeaders)
|
||||||
if (match.Success)
|
|
||||||
{
|
{
|
||||||
result[match.Groups[1].Value] = match.Groups[2].Value;
|
var match = RegexSetCookie.Match(cookie);
|
||||||
|
if (match.Success)
|
||||||
|
{
|
||||||
|
result[match.Groups[1].Value] = match.Groups[2].Value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -158,6 +158,8 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
|
||||||
{
|
{
|
||||||
var requestBuilder = new HttpRequestBuilder(false, settings.Host, settings.Port)
|
var requestBuilder = new HttpRequestBuilder(false, settings.Host, settings.Port)
|
||||||
.Resource("/gui/")
|
.Resource("/gui/")
|
||||||
|
.KeepAlive()
|
||||||
|
.SetHeader("Cache-Control", "no-cache")
|
||||||
.Accept(HttpAccept.Json);
|
.Accept(HttpAccept.Json);
|
||||||
|
|
||||||
requestBuilder.NetworkCredential = new NetworkCredential(settings.Username, settings.Password);
|
requestBuilder.NetworkCredential = new NetworkCredential(settings.Username, settings.Password);
|
||||||
|
@ -248,7 +250,7 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
|
||||||
}
|
}
|
||||||
|
|
||||||
requestBuilder.SetCookies(cookies);
|
requestBuilder.SetCookies(cookies);
|
||||||
requestBuilder.AddQueryParam("token", authToken, true);
|
requestBuilder.AddPrefixQueryParam("token", authToken, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue