Files
yavsc/src/Api/Helpers/RequestHelpers.cs
Paul Schneider e6f8947c08
Some checks failed
Dotnet build and test / log-the-inputs (push) Successful in 9s
Dotnet build and test / build (push) Failing after 1m33s
misc
2025-07-07 07:49:18 +01:00

29 lines
785 B
C#

using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Yavsc.ViewModels;
using Yavsc.Models;
using System.Linq;
namespace Yavsc.Api.Helpers
{
public static class RequestHelpers
{
// Check for some apache proxy header, if any
public static string? ForwardedFor(this HttpRequest request) {
string? host = request.Headers["X-Forwarded-For"];
if (string.IsNullOrEmpty(host)) {
host = request.Host.Value;
} else { // Using X-Forwarded-For last address
host = host.Split(',')
.Last()
.Trim();
}
return host;
}
}
}