[backend/core] Add support for HTTP proxy authentication

This commit is contained in:
Laura Hausmann 2025-01-12 08:34:07 +01:00
parent ea7bcfa652
commit 09919bdc77
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
3 changed files with 15 additions and 2 deletions

View file

@ -71,6 +71,8 @@ public sealed class Config
public sealed class NetworkSection
{
public string? HttpProxy { get; init; } = null;
public string? HttpProxyUser { get; init; } = null!;
public string? HttpProxyPass { get; init; } = null!;
}
public sealed class DatabaseSection

View file

@ -37,7 +37,16 @@ public class CustomHttpClient : HttpClient, IService<HttpClient>, ISingletonServ
ILoggerFactory loggerFactory
)
{
var proxy = network.Value.HttpProxy != null ? new WebProxy(network.Value.HttpProxy) : null;
// Configure HTTP proxy, if enabled
WebProxy? proxy = null;
if (network.Value.HttpProxy != null)
{
var creds = network.Value.HttpProxyUser != null || network.Value.HttpProxyPass != null
? new NetworkCredential(network.Value.HttpProxyUser, network.Value.HttpProxyPass)
: null;
proxy = new WebProxy(network.Value.HttpProxy, false, null, creds);
}
var fastFallback = new FastFallback(loggerFactory.CreateLogger<FastFallback>(), security, proxy != null);
var innerHandler = new SocketsHttpHandler
{

View file

@ -80,6 +80,8 @@ PublicPreview = Public
[Network]
;; Uncomment to use the specified HTTP proxy for all outgoing requests. Backend restart is required to apply changes.
;HttpProxy = 127.0.0.1:8080
;HttpProxyUser =
;HttpProxyPass =
[Performance]
;; Maximum number of incoming federation requests to handle concurrently.