1
0

Added White-/Blacklist Attributes, DateOnly/TimeOnly converters, TcpClientMoq

This commit is contained in:
2022-06-15 19:48:47 +02:00
parent f331be521f
commit 65bca0a922
15 changed files with 570 additions and 16 deletions

View File

@@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Http
/// <summary>
/// Retrieves the antiforgery token.
/// </summary>
/// <param name="httpContext">The web context.</param>
/// <param name="httpContext">The current <see cref="HttpContext"/>.</param>
/// <returns>Name and value of the token.</returns>
public static (string Name, string Value) GetAntiforgeryToken(this HttpContext httpContext)
{
@@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Http
/// <summary>
/// Returns the remote ip address.
/// </summary>
/// <param name="httpContext">The web context.</param>
/// <param name="httpContext">The current <see cref="HttpContext"/>.</param>
/// <param name="headerName">The name of the header to resolve the <see cref="IPAddress"/> when behind a proxy (Default: X-Forwarded-For).</param>
/// <returns>The ip address of the client.</returns>
public static IPAddress GetRemoteIpAddress(this HttpContext httpContext, string headerName = "X-Forwarded-For")
@@ -39,10 +39,22 @@ namespace Microsoft.AspNetCore.Http
return remote;
}
/// <summary>
/// Returns whether the request was made locally.
/// </summary>
/// <param name="httpContext">The current <see cref="HttpContext"/>.</param>
/// <param name="headerName">The name of the header to resolve the <see cref="IPAddress"/> when behind a proxy (Default: X-Forwarded-For).</param>
/// <returns></returns>
public static bool IsLocalRequest(this HttpContext httpContext, string headerName = "X-Forwarded-For")
{
var remoteIpAddress = httpContext.GetRemoteIpAddress(headerName);
return httpContext.Connection.LocalIpAddress.Equals(remoteIpAddress);
}
/// <summary>
/// Tries to retrieve the return url.
/// </summary>
/// <param name="httpContext"></param>
/// <param name="httpContext">The current <see cref="HttpContext"/>.</param>
/// <returns></returns>
public static string GetReturnUrl(this HttpContext httpContext)
{