From 7c82ed79077008bbd2a23fabb00f3832e6fa4848 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sun, 26 Feb 2023 17:22:04 +0530 Subject: [PATCH] Extensions: Updated GetRemoteEndPoint() to include ignoreXRealIpHeader option to ignore reading the remote IP from headers. --- DnsServerCore/Extensions.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DnsServerCore/Extensions.cs b/DnsServerCore/Extensions.cs index 630bbfef..8500ce27 100644 --- a/DnsServerCore/Extensions.cs +++ b/DnsServerCore/Extensions.cs @@ -32,7 +32,7 @@ namespace DnsServerCore { readonly static string[] HTTP_METHODS = new string[] { "GET", "POST" }; - public static IPEndPoint GetRemoteEndPoint(this HttpContext context) + public static IPEndPoint GetRemoteEndPoint(this HttpContext context, bool ignoreXRealIpHeader = false) { try { @@ -40,7 +40,7 @@ namespace DnsServerCore if (remoteIP is null) return new IPEndPoint(IPAddress.Any, 0); - if (NetUtilities.IsPrivateIP(remoteIP)) + if (!ignoreXRealIpHeader && NetUtilities.IsPrivateIP(remoteIP)) { string xRealIp = context.Request.Headers["X-Real-IP"]; if (IPAddress.TryParse(xRealIp, out IPAddress address)) @@ -78,7 +78,7 @@ namespace DnsServerCore { return endpoints.MapMethods(pattern, HTTP_METHODS, requestDelegate); } - + public static IEndpointConventionBuilder MapGetAndPost(this IEndpointRouteBuilder endpoints, string pattern, Delegate handler) { return endpoints.MapMethods(pattern, HTTP_METHODS, handler);