1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-27 02:09:59 +00:00

Send Http auth without waiting for challenge.

This commit is contained in:
Taloth Saldono 2016-03-17 20:15:53 +01:00
parent 70494c3674
commit 2d96914bfa
4 changed files with 8 additions and 16 deletions

View file

@ -41,13 +41,6 @@ public HttpResponse GetResponse(HttpRequest request, CookieContainer cookies)
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)
{
Stream responseStream = new MemoryStream();
@ -66,7 +59,7 @@ public HttpResponse GetResponse(HttpRequest request, CookieContainer cookies)
headerStream.Write(b, 0, s * n);
return s * n;
};
curlEasy.Url = request.Url.FullUri;
switch (request.Method)
{

View file

@ -15,18 +15,12 @@ public HttpResponse GetResponse(HttpRequest request, CookieContainer cookies)
//http://stackoverflow.com/questions/8490718/how-to-decompress-stream-deflated-with-java-util-zip-deflater-in-net
webRequest.AutomaticDecompression = DecompressionMethods.GZip;
webRequest.Credentials = request.NetworkCredential;
webRequest.Method = request.Method.ToString();
webRequest.UserAgent = UserAgentBuilder.UserAgent;
webRequest.KeepAlive = false;
webRequest.AllowAutoRedirect = request.AllowAutoRedirect;
webRequest.CookieContainer = cookies;
if (request.NetworkCredential != null)
{
webRequest.PreAuthenticate = true;
}
if (request.RequestTimeout != TimeSpan.Zero)
{
webRequest.Timeout = (int)Math.Ceiling(request.RequestTimeout.TotalMilliseconds);

View file

@ -33,7 +33,6 @@ public HttpRequest(string url, HttpAccept httpAccept = null)
public HttpHeader Headers { get; set; }
public byte[] ContentData { get; set; }
public string ContentSummary { get; set; }
public NetworkCredential NetworkCredential { get; set; }
public bool SuppressHttpError { get; set; }
public bool AllowAutoRedirect { get; set; }
public Dictionary<string, string> Cookies { get; private set; }

View file

@ -98,7 +98,13 @@ protected virtual void Apply(HttpRequest request)
request.Method = Method;
request.SuppressHttpError = SuppressHttpError;
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)
{