Send Http auth without waiting for challenge.
This commit is contained in:
parent
70494c3674
commit
2d96914bfa
|
@ -41,13 +41,6 @@ namespace NzbDrone.Common.Http.Dispatchers
|
||||||
throw new ApplicationException("Curl failed to initialize.");
|
throw new ApplicationException("Curl failed to initialize.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.NetworkCredential != null)
|
|
||||||
{
|
|
||||||
var authInfo = request.NetworkCredential.UserName + ":" + request.NetworkCredential.Password;
|
|
||||||
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
|
|
||||||
request.Headers["Authorization"] = "Basic " + authInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
lock (CurlGlobalHandle.Instance)
|
lock (CurlGlobalHandle.Instance)
|
||||||
{
|
{
|
||||||
Stream responseStream = new MemoryStream();
|
Stream responseStream = new MemoryStream();
|
||||||
|
|
|
@ -15,18 +15,12 @@ namespace NzbDrone.Common.Http.Dispatchers
|
||||||
//http://stackoverflow.com/questions/8490718/how-to-decompress-stream-deflated-with-java-util-zip-deflater-in-net
|
//http://stackoverflow.com/questions/8490718/how-to-decompress-stream-deflated-with-java-util-zip-deflater-in-net
|
||||||
webRequest.AutomaticDecompression = DecompressionMethods.GZip;
|
webRequest.AutomaticDecompression = DecompressionMethods.GZip;
|
||||||
|
|
||||||
webRequest.Credentials = request.NetworkCredential;
|
|
||||||
webRequest.Method = request.Method.ToString();
|
webRequest.Method = request.Method.ToString();
|
||||||
webRequest.UserAgent = UserAgentBuilder.UserAgent;
|
webRequest.UserAgent = UserAgentBuilder.UserAgent;
|
||||||
webRequest.KeepAlive = false;
|
webRequest.KeepAlive = false;
|
||||||
webRequest.AllowAutoRedirect = request.AllowAutoRedirect;
|
webRequest.AllowAutoRedirect = request.AllowAutoRedirect;
|
||||||
webRequest.CookieContainer = cookies;
|
webRequest.CookieContainer = cookies;
|
||||||
|
|
||||||
if (request.NetworkCredential != null)
|
|
||||||
{
|
|
||||||
webRequest.PreAuthenticate = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request.RequestTimeout != TimeSpan.Zero)
|
if (request.RequestTimeout != TimeSpan.Zero)
|
||||||
{
|
{
|
||||||
webRequest.Timeout = (int)Math.Ceiling(request.RequestTimeout.TotalMilliseconds);
|
webRequest.Timeout = (int)Math.Ceiling(request.RequestTimeout.TotalMilliseconds);
|
||||||
|
|
|
@ -33,7 +33,6 @@ namespace NzbDrone.Common.Http
|
||||||
public HttpHeader Headers { get; set; }
|
public HttpHeader Headers { get; set; }
|
||||||
public byte[] ContentData { get; set; }
|
public byte[] ContentData { get; set; }
|
||||||
public string ContentSummary { get; set; }
|
public string ContentSummary { get; set; }
|
||||||
public NetworkCredential NetworkCredential { get; set; }
|
|
||||||
public bool SuppressHttpError { get; set; }
|
public bool SuppressHttpError { get; set; }
|
||||||
public bool AllowAutoRedirect { get; set; }
|
public bool AllowAutoRedirect { get; set; }
|
||||||
public Dictionary<string, string> Cookies { get; private set; }
|
public Dictionary<string, string> Cookies { get; private set; }
|
||||||
|
|
|
@ -98,7 +98,13 @@ namespace NzbDrone.Common.Http
|
||||||
request.Method = Method;
|
request.Method = Method;
|
||||||
request.SuppressHttpError = SuppressHttpError;
|
request.SuppressHttpError = SuppressHttpError;
|
||||||
request.AllowAutoRedirect = AllowAutoRedirect;
|
request.AllowAutoRedirect = AllowAutoRedirect;
|
||||||
request.NetworkCredential = NetworkCredential;
|
|
||||||
|
if (NetworkCredential != null)
|
||||||
|
{
|
||||||
|
var authInfo = NetworkCredential.UserName + ":" + NetworkCredential.Password;
|
||||||
|
authInfo = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(authInfo));
|
||||||
|
request.Headers.Set("Authorization", "Basic " + authInfo);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var header in Headers)
|
foreach (var header in Headers)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue