also expose the request client IP as seen by server port

master
UbitUmarov 2020-04-13 14:34:03 +01:00
parent e0ba96055c
commit b419f71a68
7 changed files with 21 additions and 9 deletions

View File

@ -55,6 +55,7 @@ namespace OpenSim.Framework.Servers.HttpServer
Dictionary<string, string> QueryAsDictionary { get; } //faster than Query
string RawUrl { get; }
IPEndPoint RemoteIPEndPoint { get; }
IPEndPoint LocalIPEndPoint { get; }
Uri Url { get; }
string UserAgent { get; }
}

View File

@ -89,7 +89,7 @@ namespace OSHttpServer
/// </summary>
public event EventHandler Started;
public IPEndPoint LocalRemoteEndPoint {get; set;}
public IPEndPoint LocalIPEndPoint {get; set;}
/// <summary>
/// Initializes a new instance of the <see cref="HttpClientContext"/> 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;

View File

@ -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();

View File

@ -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;
}

View File

@ -16,7 +16,7 @@ namespace OSHttpServer
/// </summary>
string SSLCommonName { get; }
IPEndPoint LocalRemoteEndPoint {get; set;}
IPEndPoint LocalIPEndPoint {get; set;}
/// <summary>
/// Using SSL or other encryption method.

View File

@ -136,6 +136,7 @@ namespace OSHttpServer
/// <param name="cookies">The cookies.</param>
void SetCookies(RequestCookies cookies);
IPEndPoint LocalIPEndPoint { get; }
IPEndPoint RemoteIPEndPoint { get; }
}
}

View File

@ -165,7 +165,15 @@ namespace OpenSim.Tests.Common
{
get
{
throw new NotImplementedException ();
throw new NotImplementedException();
}
}
public IPEndPoint LocalIPEndPoint
{
get
{
throw new NotImplementedException();
}
}