C# extension method to get the first of default HTTP header from an HttpRequest instance.
public static class HttpRequestExtensions
{
public static string? FirstOrDefaultHeader(this HttpRequest request, string key)
{
return request.Headers.FirstOrDefault(h => h.Key == key).Value.FirstOrDefault();
}
}