Skip to content

Commit

Permalink
New: Pass general proxy credentials to FlareSolverr
Browse files Browse the repository at this point in the history
Fixes #2073
  • Loading branch information
mynameisbogdan committed Mar 19, 2024
1 parent 7d5d338 commit d279c97
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/NzbDrone.Core/IndexerProxies/FlareSolverr/FlareSolverr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,15 @@ private HttpRequest GenerateFlareSolverrRequest(HttpRequest request)
var url = request.Url.ToString();
var maxTimeout = Settings.RequestTimeout * 1000;

// Use Proxy if no credentials are set (creds not supported as of FS 2.2.9)
var proxySettings = _proxySettingsProvider.GetProxySettings();
var proxyUrl = proxySettings != null && proxySettings.Username.IsNullOrWhiteSpace() && proxySettings.Password.IsNullOrWhiteSpace() ? GetProxyUri(proxySettings) : null;
var proxyUrl = proxySettings != null ? GetProxyUri(proxySettings) : null;

var requestProxy = new FlareSolverrProxy
{
Url = proxyUrl?.OriginalString,
Username = proxySettings != null && proxySettings.Username.IsNotNullOrWhiteSpace() ? proxySettings.Username : null,
Password = proxySettings != null && proxySettings.Password.IsNotNullOrWhiteSpace() ? proxySettings.Password : null
};

if (request.Method == HttpMethod.Get)
{
Expand All @@ -113,10 +119,7 @@ private HttpRequest GenerateFlareSolverrRequest(HttpRequest request)
Cmd = "request.get",
Url = url,
MaxTimeout = maxTimeout,
Proxy = new FlareSolverrProxy
{
Url = proxyUrl?.OriginalString
}
Proxy = requestProxy
};
}
else if (request.Method == HttpMethod.Post)
Expand All @@ -139,10 +142,7 @@ private HttpRequest GenerateFlareSolverrRequest(HttpRequest request)
ContentLength = null
},
MaxTimeout = maxTimeout,
Proxy = new FlareSolverrProxy
{
Url = proxyUrl?.OriginalString
}
Proxy = requestProxy
};
}
else if (contentTypeType.Contains("multipart/form-data")
Expand All @@ -169,6 +169,7 @@ private HttpRequest GenerateFlareSolverrRequest(HttpRequest request)
newRequest.LogResponseContent = true;
newRequest.RequestTimeout = TimeSpan.FromSeconds(Settings.RequestTimeout + 5);
newRequest.SetContent(req.ToJson());
newRequest.ContentSummary = req.ToJson(Formatting.None);

_logger.Debug("Cloudflare Detected, Applying FlareSolverr Proxy {0} to request {1}", Name, request.Url);

Expand Down Expand Up @@ -243,6 +244,8 @@ private class FlareSolverrRequestPostUrlEncoded : FlareSolverrRequestPost
private class FlareSolverrProxy
{
public string Url { get; set; }
public string Username { get; set; }
public string Password { get; set; }
}

private class HeadersPost
Expand Down

0 comments on commit d279c97

Please sign in to comment.