1
0

Adding support for .NET 8.0 LTS, renaming private fields to start with underscore

This commit is contained in:
2023-12-29 01:58:40 +01:00
parent 8bd511a936
commit 99d3f7758a
59 changed files with 922 additions and 871 deletions

View File

@@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Http
public static class HttpContextExtensions
{
// Search these additional headers for a remote client ip address.
private static readonly string[] defaultIpHeaderNames = new[]
private static readonly string[] _defaultIpHeaderNames = new[]
{
"Cf-Connecting-Ip", // set by Cloudflare
"X-Real-IP", // wide-spread alternative to X-Forwarded-For
@@ -51,8 +51,8 @@ namespace Microsoft.AspNetCore.Http
string forwardedForAddress = null;
var headerNames = string.IsNullOrWhiteSpace(ipHeaderName)
? defaultIpHeaderNames
: new[] { ipHeaderName }.Concat(defaultIpHeaderNames);
? _defaultIpHeaderNames
: new[] { ipHeaderName }.Concat(_defaultIpHeaderNames);
foreach (string headerName in headerNames)
{
if (!httpContext.Request.Headers.ContainsKey(headerName))
@@ -67,9 +67,15 @@ namespace Microsoft.AspNetCore.Http
}
if (!string.IsNullOrWhiteSpace(forwardedForAddress) && IPAddress.TryParse(forwardedForAddress, out var remoteAddress))
return remoteAddress.IsIPv4MappedToIPv6 ? remoteAddress.MapToIPv4() : remoteAddress;
{
return remoteAddress.IsIPv4MappedToIPv6
? remoteAddress.MapToIPv4()
: remoteAddress;
}
return httpContext.Connection.RemoteIpAddress;
return httpContext.Connection.RemoteIpAddress.IsIPv4MappedToIPv6
? httpContext.Connection.RemoteIpAddress.MapToIPv4()
: httpContext.Connection.RemoteIpAddress;
}
/// <summary>