< Summary

Information
Class: Elsa.Extensions.HttpRequestExtensions
Assembly: Elsa.Api.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/common/Elsa.Api.Common/Extensions/HttpContextAccessorExtensions.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 6
Coverable lines: 6
Total lines: 25
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
IsLocal(...)0%4260%

File(s)

/home/runner/work/elsa-core/elsa-core/src/common/Elsa.Api.Common/Extensions/HttpContextAccessorExtensions.cs

#LineLine coverage
 1using System.Net;
 2using Microsoft.AspNetCore.Http;
 3
 4namespace Elsa.Extensions;
 5
 6/// <summary>
 7/// Extension methods for <see cref="HttpRequest"/>.
 8/// </summary>
 9public static class HttpRequestExtensions
 10{
 11    /// <summary>
 12    /// Returns a value indicating whether the specified request is a local request.
 13    /// </summary>
 14    /// <param name="request"></param>
 15    /// <returns>True if the request is local, otherwise false.</returns>
 16    public static bool IsLocal(this HttpRequest request)
 17    {
 018        var connection = request.HttpContext.Connection;
 019        return connection.RemoteIpAddress != null
 020            ? connection.LocalIpAddress != null
 021                ? connection.RemoteIpAddress.Equals(connection.LocalIpAddress)
 022                : IPAddress.IsLoopback(connection.RemoteIpAddress)
 023            : connection.RemoteIpAddress == null && connection.LocalIpAddress == null;
 24    }
 25}