From b419f71a688ea897ce66cab1be7eec25dd97aeda Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 13 Apr 2020 14:34:03 +0100 Subject: [PATCH] also expose the request client IP as seen by server port --- .../Servers/HttpServer/Interfaces/IOSHttpRequest.cs | 1 + .../HttpServer/OSHttpServer/HttpClientContext.cs | 8 ++++---- .../HttpServer/OSHttpServer/HttpContextFactory.cs | 2 +- .../Servers/HttpServer/OSHttpServer/HttpRequest.cs | 6 ++++-- .../HttpServer/OSHttpServer/IHttpClientContext.cs | 2 +- .../Servers/HttpServer/OSHttpServer/IHttpRequest.cs | 1 + OpenSim/Tests/Common/Mock/TestOSHttpRequest.cs | 10 +++++++++- 7 files changed, 21 insertions(+), 9 deletions(-) diff --git a/OpenSim/Framework/Servers/HttpServer/Interfaces/IOSHttpRequest.cs b/OpenSim/Framework/Servers/HttpServer/Interfaces/IOSHttpRequest.cs index 875f04b353..39dc6faa56 100644 --- a/OpenSim/Framework/Servers/HttpServer/Interfaces/IOSHttpRequest.cs +++ b/OpenSim/Framework/Servers/HttpServer/Interfaces/IOSHttpRequest.cs @@ -55,6 +55,7 @@ namespace OpenSim.Framework.Servers.HttpServer Dictionary QueryAsDictionary { get; } //faster than Query string RawUrl { get; } IPEndPoint RemoteIPEndPoint { get; } + IPEndPoint LocalIPEndPoint { get; } Uri Url { get; } string UserAgent { get; } } diff --git a/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpClientContext.cs b/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpClientContext.cs index 338faaf1a3..bd8b413fe3 100644 --- a/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpClientContext.cs +++ b/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpClientContext.cs @@ -89,7 +89,7 @@ namespace OSHttpServer /// public event EventHandler Started; - public IPEndPoint LocalRemoteEndPoint {get; set;} + public IPEndPoint LocalIPEndPoint {get; set;} /// /// Initializes a new instance of the class. @@ -107,7 +107,7 @@ namespace OSHttpServer if (!stream.CanWrite || !stream.CanRead) throw new ArgumentException("Stream must be writable and readable."); - LocalRemoteEndPoint = remoteEndPoint; + LocalIPEndPoint = remoteEndPoint; _log = NullLogWriter.Instance; m_parser = parserFactory.CreateParser(_log); m_parser.RequestCompleted += OnRequestCompleted; @@ -186,8 +186,8 @@ namespace OSHttpServer m_currentRequest.Method = e.HttpMethod; m_currentRequest.HttpVersion = e.HttpVersion; m_currentRequest.UriPath = e.UriPath; - m_currentRequest.AddHeader("remote_addr", LocalRemoteEndPoint.Address.ToString()); - m_currentRequest.AddHeader("remote_port", LocalRemoteEndPoint.Port.ToString()); + m_currentRequest.AddHeader("remote_addr", LocalIPEndPoint.Address.ToString()); + m_currentRequest.AddHeader("remote_port", LocalIPEndPoint.Port.ToString()); FirstRequestLineReceived = true; TriggerKeepalive = false; diff --git a/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpContextFactory.cs b/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpContextFactory.cs index 6937aa8e3e..eb951e24e4 100644 --- a/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpContextFactory.cs +++ b/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpContextFactory.cs @@ -54,7 +54,7 @@ namespace OSHttpServer context.Stream = stream; context.IsSecured = isSecured; - context.LocalRemoteEndPoint = endPoint; + context.LocalIPEndPoint = endPoint; ContextTimeoutManager.StartMonitoringContext(context); m_activeContexts[context.contextID] = context; context.Start(); diff --git a/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpRequest.cs b/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpRequest.cs index 9a25402048..e648ea49a2 100644 --- a/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpRequest.cs +++ b/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpRequest.cs @@ -271,6 +271,8 @@ namespace OSHttpServer Cookies = cookies; } + public IPEndPoint LocalIPEndPoint { get {return m_context.LocalIPEndPoint; }} + public IPEndPoint RemoteIPEndPoint { get @@ -280,7 +282,7 @@ namespace OSHttpServer string addr = m_headers["x-forwarded-for"]; if(!string.IsNullOrEmpty(addr)) { - int port = m_context.LocalRemoteEndPoint.Port; + int port = m_context.LocalIPEndPoint.Port; try { m_remoteIPEndPoint = new IPEndPoint(IPAddress.Parse(addr), port); @@ -292,7 +294,7 @@ namespace OSHttpServer } } if (m_remoteIPEndPoint == null) - m_remoteIPEndPoint = m_context.LocalRemoteEndPoint; + m_remoteIPEndPoint = m_context.LocalIPEndPoint; return m_remoteIPEndPoint; } diff --git a/OpenSim/Framework/Servers/HttpServer/OSHttpServer/IHttpClientContext.cs b/OpenSim/Framework/Servers/HttpServer/OSHttpServer/IHttpClientContext.cs index 99ae8d7dba..60e7527dc3 100644 --- a/OpenSim/Framework/Servers/HttpServer/OSHttpServer/IHttpClientContext.cs +++ b/OpenSim/Framework/Servers/HttpServer/OSHttpServer/IHttpClientContext.cs @@ -16,7 +16,7 @@ namespace OSHttpServer /// string SSLCommonName { get; } - IPEndPoint LocalRemoteEndPoint {get; set;} + IPEndPoint LocalIPEndPoint {get; set;} /// /// Using SSL or other encryption method. diff --git a/OpenSim/Framework/Servers/HttpServer/OSHttpServer/IHttpRequest.cs b/OpenSim/Framework/Servers/HttpServer/OSHttpServer/IHttpRequest.cs index 5d43aa55b7..d407f6f0a8 100644 --- a/OpenSim/Framework/Servers/HttpServer/OSHttpServer/IHttpRequest.cs +++ b/OpenSim/Framework/Servers/HttpServer/OSHttpServer/IHttpRequest.cs @@ -136,6 +136,7 @@ namespace OSHttpServer /// The cookies. void SetCookies(RequestCookies cookies); + IPEndPoint LocalIPEndPoint { get; } IPEndPoint RemoteIPEndPoint { get; } } } \ No newline at end of file diff --git a/OpenSim/Tests/Common/Mock/TestOSHttpRequest.cs b/OpenSim/Tests/Common/Mock/TestOSHttpRequest.cs index 83ea13d500..21db639817 100644 --- a/OpenSim/Tests/Common/Mock/TestOSHttpRequest.cs +++ b/OpenSim/Tests/Common/Mock/TestOSHttpRequest.cs @@ -165,7 +165,15 @@ namespace OpenSim.Tests.Common { get { - throw new NotImplementedException (); + throw new NotImplementedException(); + } + } + + public IPEndPoint LocalIPEndPoint + { + get + { + throw new NotImplementedException(); } }