From ed4241583f60ff43209b7c6e7c966efc6d96280e Mon Sep 17 00:00:00 2001 From: Dr Scofield Date: Thu, 17 Jul 2008 12:54:15 +0000 Subject: morphing OSHttpHandler interface into an abstract base class. adding HTTP method matching support. adapting OSHttpXmlRpcHandler accordingly. dropping OSHttpXmlProcessor delegate in favour of good old XmlRpcMethodHandler delegate (was the same signature). --- OpenSim/Framework/Servers/OSHttpHandler.cs | 99 ++++++++++++++++++++++++------ 1 file changed, 79 insertions(+), 20 deletions(-) (limited to 'OpenSim/Framework/Servers/OSHttpHandler.cs') diff --git a/OpenSim/Framework/Servers/OSHttpHandler.cs b/OpenSim/Framework/Servers/OSHttpHandler.cs index a9f42f3..8b65438 100644 --- a/OpenSim/Framework/Servers/OSHttpHandler.cs +++ b/OpenSim/Framework/Servers/OSHttpHandler.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Text.RegularExpressions; namespace OpenSim.Framework.Servers @@ -43,16 +44,10 @@ namespace OpenSim.Framework.Servers /// handler did not process the request /// /// - /// Handled + /// Done /// handler did process the request, OSHttpServer /// can clean up and close the request /// - /// - /// Detached - /// handler handles the request, OSHttpServer - /// can forget about the request and should not touch it as - /// the handler has taken control - /// /// /// public enum OSHttpHandlerResult @@ -71,26 +66,41 @@ namespace OpenSim.Framework.Servers /// false otherwise public delegate bool OSHttpContentTypeChecker(OSHttpRequest req); - public interface OSHttpHandler + public abstract class OSHttpHandler { /// - /// Regular expression used to match against path of incoming - /// HTTP request. If you want to match any string either use - /// '.*' or null. To match for the emtpy string use '^$' + /// Regular expression used to match against method of + /// the incoming HTTP request. If you want to match any string + /// either use '.*' or null. To match on the empty string use + /// '^$'. /// - Regex Path + public virtual Regex Method { - get; + get { return _method; } } + protected Regex _method; + + /// + /// Regular expression used to match against path of the + /// incoming HTTP request. If you want to match any string + /// either use '.*' or null. To match on the emtpy string use + /// '^$'. + /// + public virtual Regex Path + { + get { return _path; } + } + protected Regex _path; /// /// Dictionary of (header name, regular expression) tuples, /// allowing us to match on HTTP header fields. /// - Dictionary Headers + public virtual Dictionary Headers { - get; + get { return _headers; } } + protected Dictionary _headers; /// /// Dictionary of (header name, regular expression) tuples, @@ -101,10 +111,11 @@ namespace OpenSim.Framework.Servers /// (trivial) changes to HttpServer.HttpListener that have not /// been implemented. /// - Regex IPEndPointWhitelist + public virtual Regex IPEndPointWhitelist { - get; + get { return _ipEndPointRegex; } } + protected Regex _ipEndPointRegex; /// @@ -114,11 +125,59 @@ namespace OpenSim.Framework.Servers /// /// true if the handler is interested in the content; /// false otherwise - OSHttpContentTypeChecker ContentTypeChecker + internal virtual OSHttpContentTypeChecker ContentTypeChecker { - get; + get { return null; } + } + + /// + /// Base class constructor. + /// + /// null or path regex + /// null or dictionary of header + /// regexs + /// null or content type + /// regex + /// null or IP address regex + public OSHttpHandler(Regex method, Regex path, Dictionary headers, Regex contentType, Regex whitelist) + { + _method = method; + _path = path; + _ipEndPointRegex = whitelist; + + if (null == _headers && null != contentType) + { + _headers = new Dictionary(); + _headers.Add("content-type", contentType); + } } - OSHttpHandlerResult Process(OSHttpRequest request); + + /// + /// Process an incoming OSHttpRequest that matched our + /// requirements. + /// + /// + /// OSHttpHandlerResult.Pass if we are after all not + /// interested in the request; OSHttpHandlerResult.Done if we + /// did process the request. + /// + public abstract OSHttpHandlerResult Process(OSHttpRequest request); + + public override string ToString() + { + StringWriter sw = new StringWriter(); + sw.WriteLine("{0}", base.ToString()); + sw.WriteLine(" method regex {0}", null == Method ? "null" : Method.ToString()); + sw.WriteLine(" path regex {0}", null == Path ? "null": Path.ToString()); + foreach (string tag in Headers.Keys) + { + sw.WriteLine(" header {0} : {1}", tag, Headers[tag].ToString()); + } + sw.WriteLine(" IP whitelist {0}", null == IPEndPointWhitelist ? "null" : IPEndPointWhitelist.ToString()); + sw.WriteLine(); + sw.Close(); + return sw.ToString(); + } } } \ No newline at end of file -- cgit v1.1