mirror of
https://github.com/opensim/opensim.git
synced 2026-08-08 10:15:33 +08:00
status: work in progress, non-functional
having OSHttpHandler as a delegate was not too hot, i'm refactoring it into an interface.
This commit is contained in:
@@ -40,39 +40,6 @@ using HttpListener = HttpServer.HttpListener;
|
||||
|
||||
namespace OpenSim.Framework.Servers
|
||||
{
|
||||
/// <sumary>
|
||||
/// Any OSHttpHandler must return one of the following results:
|
||||
/// <list type = "table">
|
||||
/// <listheader>
|
||||
/// <term>result code</term>
|
||||
/// <description>meaning</description>
|
||||
/// </listheader>
|
||||
/// <item>
|
||||
/// <term>Pass</term>
|
||||
/// <description>handler did not process the request</request>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>Handled</term>
|
||||
/// <description>handler did process the request, OSHttpServer
|
||||
/// can clean up and close the request</request>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>Detached</term>
|
||||
/// <description>handler handles the request, OSHttpServer
|
||||
/// can forget about the request and should not touch it as
|
||||
/// the handler has taken control</request>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public enum OSHttpHandlerResult
|
||||
{
|
||||
Pass,
|
||||
Handled,
|
||||
Detached,
|
||||
}
|
||||
|
||||
public delegate OSHttpHandlerResult OSHttpHandler(OSHttpRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// OSHttpServer provides an HTTP server bound to a specific
|
||||
/// port. When instantiated with just address and port it uses
|
||||
@@ -81,7 +48,7 @@ namespace OpenSim.Framework.Servers
|
||||
/// </summary>
|
||||
public class OSHttpServer
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
// underlying HttpServer.HttpListener
|
||||
protected HttpListener _listener;
|
||||
@@ -116,6 +83,22 @@ namespace OpenSim.Framework.Servers
|
||||
get { return _pumps.Length; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List of registered OSHttpHandlers for this OSHttpServer instance.
|
||||
/// </summary>
|
||||
protected List<OSHttpHandler> _httpHandlers = new List<OSHttpHandler>();
|
||||
public List<OSHttpHandler> OSHttpHandlers
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_httpHandlers)
|
||||
{
|
||||
return new List<OSHttpHandler>(_httpHandlers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Instantiate an HTTP server.
|
||||
/// </summary>
|
||||
@@ -182,9 +165,6 @@ namespace OpenSim.Framework.Servers
|
||||
}
|
||||
}
|
||||
|
||||
protected Dictionary<OSHttpHandler, Regex> Handler2Path = new Dictionary<OSHttpHandler, Regex>();
|
||||
protected Dictionary<OSHttpHandler, Dictionary<string, Regex>> Handler2Headers =
|
||||
new Dictionary<OSHttpHandler, Dictionary<string, Regex>>();
|
||||
|
||||
/// <summary>
|
||||
/// Add an HTTP request handler.
|
||||
@@ -193,13 +173,17 @@ namespace OpenSim.Framework.Servers
|
||||
/// <param name="path">regex object for path matching</parm>
|
||||
/// <param name="headers">dictionary containing header names
|
||||
/// and regular expressions to match against header values</param>
|
||||
public void AddHandler(OSHttpHandler handler, Regex path, Dictionary<string, Regex> headers)
|
||||
public void AddHandler(OSHttpHandler handler)
|
||||
{
|
||||
lock (Handler2Headers)
|
||||
lock (_httpHandlers)
|
||||
{
|
||||
|
||||
if (_httpHandlers.Contains(handler))
|
||||
{
|
||||
_log.DebugFormat("[OSHttpServer] attempt to add already existing handler ignored");
|
||||
return;
|
||||
}
|
||||
_httpHandlers.Add(handler);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user