From 514a3230563e19708588945f90e81760377f1265 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Thu, 29 Mar 2007 19:05:34 +0000 Subject: * RestMethod now uses same pattern as XmlRpcMethod * Made /Admin use RestMethod * HttpServer is now a mini-webapp-server yay! --- Servers/BaseHttpServer.cs | 37 +++++++++++++++++++------------------ Servers/IRestHandler.cs | 5 +---- 2 files changed, 20 insertions(+), 22 deletions(-) (limited to 'Servers') diff --git a/Servers/BaseHttpServer.cs b/Servers/BaseHttpServer.cs index bac7e86..7c2a195 100644 --- a/Servers/BaseHttpServer.cs +++ b/Servers/BaseHttpServer.cs @@ -14,7 +14,7 @@ namespace OpenSim.Servers { protected Thread m_workerThread; protected HttpListener m_httpListener; - protected Dictionary m_restHandlers = new Dictionary(); + protected Dictionary m_restHandlers = new Dictionary(); protected Dictionary m_rpcHandlers = new Dictionary(); protected int m_port; @@ -23,11 +23,13 @@ namespace OpenSim.Servers m_port = port; } - public bool AddRestHandler(string path, IRestHandler handler) + public bool AddRestHandler(string method, string path, RestMethod handler) { - if (!this.m_restHandlers.ContainsKey(path)) + string methodKey = String.Format("{0}: {1}", method, path); + + if (!this.m_restHandlers.ContainsKey(methodKey)) { - this.m_restHandlers.Add(path, handler); + this.m_restHandlers.Add(methodKey, handler); return true; } @@ -69,25 +71,24 @@ namespace OpenSim.Servers return XmlRpcResponseSerializer.Singleton.Serialize(response); } - protected virtual string ParseREST(string requestBody, string requestURL, string requestMethod) + protected virtual string ParseREST(string request, string path, string method) { - string[] path; - string pathDelimStr = "/"; - char[] pathDelimiter = pathDelimStr.ToCharArray(); - path = requestURL.Split(pathDelimiter); - - string responseString = ""; + string response; + RestMethod handler; + + string methodKey = String.Format("{0}: {1}", method, path); - //path[0] should be empty so we are interested in path[1] - if (path.Length > 1) + if (m_restHandlers.TryGetValue(methodKey, out handler)) { - if ((path[1] != "") && (this.m_restHandlers.ContainsKey(path[1]))) - { - responseString = this.m_restHandlers[path[1]].HandleREST(requestBody, requestURL, requestMethod); - } + response = handler(request); + + } + else + { + response = String.Empty; } - return responseString; + return response; } protected virtual string ParseLLSDXML(string requestBody) diff --git a/Servers/IRestHandler.cs b/Servers/IRestHandler.cs index f269600..deb77d8 100644 --- a/Servers/IRestHandler.cs +++ b/Servers/IRestHandler.cs @@ -4,8 +4,5 @@ using System.Text; namespace OpenSim.CAPS { - public interface IRestHandler - { - string HandleREST(string requestBody, string requestURL, string requestMethod); - } + public delegate string RestMethod( string request ); } -- cgit v1.1