using System.Net;
using Microsoft.AspNetCore.Http;
namespace Elsa.Extensions;
///
/// Extension methods for .
///
public static class HttpRequestExtensions
{
///
/// Returns a value indicating whether the specified request is a local request.
///
///
/// True if the request is local, otherwise false.
public static bool IsLocal(this HttpRequest request)
{
var connection = request.HttpContext.Connection;
return connection.RemoteIpAddress != null
? connection.LocalIpAddress != null
? connection.RemoteIpAddress.Equals(connection.LocalIpAddress)
: IPAddress.IsLoopback(connection.RemoteIpAddress)
: connection.RemoteIpAddress == null && connection.LocalIpAddress == null;
}
}