1
0

Moved all UnitTests to a single project. Implemented parts of AspNetCore UnitTests.

This commit is contained in:
2022-07-17 12:21:05 +02:00
parent 73038bbe5a
commit a26d6a0036
46 changed files with 2411 additions and 105 deletions

View File

@@ -30,13 +30,11 @@ namespace Microsoft.AspNetCore.Http
/// <returns>The ip address of the client.</returns>
public static IPAddress GetRemoteIpAddress(this HttpContext httpContext, string headerName = "X-Forwarded-For")
{
var remote = httpContext.Connection.RemoteIpAddress;
string forwardedHeader = httpContext.Request.Headers[headerName].ToString();
if (!string.IsNullOrWhiteSpace(forwardedHeader) && IPAddress.TryParse(forwardedHeader, out var forwarded))
return forwarded;
return remote;
return httpContext.Connection.RemoteIpAddress;
}
/// <summary>
@@ -58,11 +56,13 @@ namespace Microsoft.AspNetCore.Http
/// <returns></returns>
public static string GetReturnUrl(this HttpContext httpContext)
{
string url = httpContext.Items["OriginalRequest"]?.ToString();
if (string.IsNullOrWhiteSpace(url))
url = httpContext.Request.Query["ReturnUrl"].ToString();
if (httpContext.Items.ContainsKey("OriginalRequest"))
return httpContext.Items["OriginalRequest"].ToString();
return url;
if (httpContext.Request.Query.ContainsKey("ReturnUrl"))
return httpContext.Request.Query["ReturnUrl"].ToString();
return null;
}
/// <summary>
@@ -70,6 +70,6 @@ namespace Microsoft.AspNetCore.Http
/// </summary>
/// <param name="httpContext">The current <see cref="HttpContext"/>.</param>
public static void ClearSession(this HttpContext httpContext)
=> httpContext?.Session?.Clear();
=> httpContext.Session?.Clear();
}
}