yavsc/src/Yavsc.Api/Helpers/RequestHelpers.cs

18 lines
564 B
C#
Raw Normal View History

2025-02-17 23:56:28 +00:00
namespace Yavsc.Api.Helpers
2019-07-21 02:39:57 +02:00
{
public static class RequestHelpers
{
// Check for some apache proxy header, if any
2025-07-07 07:49:18 +01:00
public static string? ForwardedFor(this HttpRequest request) {
string? host = request.Headers["X-Forwarded-For"];
2019-07-21 02:39:57 +02:00
if (string.IsNullOrEmpty(host)) {
host = request.Host.Value;
} else { // Using X-Forwarded-For last address
host = host.Split(',')
.Last()
.Trim();
}
return host;
}
}
2023-03-19 17:57:55 +00:00
}