yavsc/src/Api/Helpers/RequestHelpers.cs

28 lines
778 B
C#
Raw Normal View History

2019-07-21 02:39:57 +02:00
using System.Collections.Generic;
using Microsoft.Extensions.Logging;
2023-03-19 17:57:55 +00:00
using Microsoft.AspNetCore.Http;
2019-07-21 02:39:57 +02:00
using System.Threading.Tasks;
using Newtonsoft.Json;
using Yavsc.ViewModels;
using Yavsc.Models;
using System.Linq;
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
public static string ForHost(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;
}
}
2023-03-19 17:57:55 +00:00
}