mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 14:10:53 +00:00
Add support for custom reverse proxy endpoints (#2003)
* Add support for custom reverse proxy endpoints * Fix missing string.Format, use KnownNetworks instead of KnownProxies * Misc
This commit is contained in:
@@ -22,8 +22,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using ArchiSteamFarm.IPC.Integration;
|
||||
using ArchiSteamFarm.Localization;
|
||||
using ArchiSteamFarm.Plugins;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
@@ -130,8 +133,47 @@ namespace ArchiSteamFarm.IPC {
|
||||
|
||||
// The order of dependency injection matters, pay attention to it
|
||||
|
||||
// Add support for custom reverse proxy endpoints
|
||||
HashSet<string>? knownNetworksText = Configuration.GetSection("Kestrel:KnownNetworks").Get<HashSet<string>>();
|
||||
|
||||
HashSet<IPNetwork>? knownNetworks = null;
|
||||
|
||||
if (knownNetworksText != null) {
|
||||
knownNetworks = new HashSet<IPNetwork>(knownNetworksText.Count);
|
||||
|
||||
foreach (string ipAddressText in knownNetworksText) {
|
||||
string[] addressParts = ipAddressText.Split('/', StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if ((addressParts.Length != 2) || !IPAddress.TryParse(addressParts[0], out IPAddress? ipAddress)) {
|
||||
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsInvalid, nameof(ipAddressText)));
|
||||
ASF.ArchiLogger.LogGenericDebug(nameof(ipAddressText) + ": " + ipAddressText);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (!byte.TryParse(addressParts[1], out byte prefixLength)) {
|
||||
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsInvalid, nameof(prefixLength)));
|
||||
ASF.ArchiLogger.LogGenericDebug(nameof(ipAddressText) + ": " + ipAddressText);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
knownNetworks.Add(new IPNetwork(ipAddress, prefixLength));
|
||||
}
|
||||
}
|
||||
|
||||
// Add support for proxies
|
||||
services.Configure<ForwardedHeadersOptions>(options => options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto);
|
||||
services.Configure<ForwardedHeadersOptions>(
|
||||
options => {
|
||||
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
|
||||
|
||||
if (knownNetworks != null) {
|
||||
foreach (IPNetwork knownNetwork in knownNetworks) {
|
||||
options.KnownNetworks.Add(knownNetwork);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Add support for response compression
|
||||
services.AddResponseCompression();
|
||||
|
||||
Reference in New Issue
Block a user