diff options
Diffstat (limited to 'Servers')
-rw-r--r-- | Servers/BaseHttpServer.cs | 37 | ||||
-rw-r--r-- | Servers/IRestHandler.cs | 5 |
2 files changed, 20 insertions, 22 deletions
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 | |||
14 | { | 14 | { |
15 | protected Thread m_workerThread; | 15 | protected Thread m_workerThread; |
16 | protected HttpListener m_httpListener; | 16 | protected HttpListener m_httpListener; |
17 | protected Dictionary<string, IRestHandler> m_restHandlers = new Dictionary<string, IRestHandler>(); | 17 | protected Dictionary<string, RestMethod> m_restHandlers = new Dictionary<string, RestMethod>(); |
18 | protected Dictionary<string, XmlRpcMethod> m_rpcHandlers = new Dictionary<string, XmlRpcMethod>(); | 18 | protected Dictionary<string, XmlRpcMethod> m_rpcHandlers = new Dictionary<string, XmlRpcMethod>(); |
19 | protected int m_port; | 19 | protected int m_port; |
20 | 20 | ||
@@ -23,11 +23,13 @@ namespace OpenSim.Servers | |||
23 | m_port = port; | 23 | m_port = port; |
24 | } | 24 | } |
25 | 25 | ||
26 | public bool AddRestHandler(string path, IRestHandler handler) | 26 | public bool AddRestHandler(string method, string path, RestMethod handler) |
27 | { | 27 | { |
28 | if (!this.m_restHandlers.ContainsKey(path)) | 28 | string methodKey = String.Format("{0}: {1}", method, path); |
29 | |||
30 | if (!this.m_restHandlers.ContainsKey(methodKey)) | ||
29 | { | 31 | { |
30 | this.m_restHandlers.Add(path, handler); | 32 | this.m_restHandlers.Add(methodKey, handler); |
31 | return true; | 33 | return true; |
32 | } | 34 | } |
33 | 35 | ||
@@ -69,25 +71,24 @@ namespace OpenSim.Servers | |||
69 | return XmlRpcResponseSerializer.Singleton.Serialize(response); | 71 | return XmlRpcResponseSerializer.Singleton.Serialize(response); |
70 | } | 72 | } |
71 | 73 | ||
72 | protected virtual string ParseREST(string requestBody, string requestURL, string requestMethod) | 74 | protected virtual string ParseREST(string request, string path, string method) |
73 | { | 75 | { |
74 | string[] path; | 76 | string response; |
75 | string pathDelimStr = "/"; | 77 | RestMethod handler; |
76 | char[] pathDelimiter = pathDelimStr.ToCharArray(); | 78 | |
77 | path = requestURL.Split(pathDelimiter); | 79 | string methodKey = String.Format("{0}: {1}", method, path); |
78 | |||
79 | string responseString = ""; | ||
80 | 80 | ||
81 | //path[0] should be empty so we are interested in path[1] | 81 | if (m_restHandlers.TryGetValue(methodKey, out handler)) |
82 | if (path.Length > 1) | ||
83 | { | 82 | { |
84 | if ((path[1] != "") && (this.m_restHandlers.ContainsKey(path[1]))) | 83 | response = handler(request); |
85 | { | 84 | |
86 | responseString = this.m_restHandlers[path[1]].HandleREST(requestBody, requestURL, requestMethod); | 85 | } |
87 | } | 86 | else |
87 | { | ||
88 | response = String.Empty; | ||
88 | } | 89 | } |
89 | 90 | ||
90 | return responseString; | 91 | return response; |
91 | } | 92 | } |
92 | 93 | ||
93 | protected virtual string ParseLLSDXML(string requestBody) | 94 | 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; | |||
4 | 4 | ||
5 | namespace OpenSim.CAPS | 5 | namespace OpenSim.CAPS |
6 | { | 6 | { |
7 | public interface IRestHandler | 7 | public delegate string RestMethod( string request ); |
8 | { | ||
9 | string HandleREST(string requestBody, string requestURL, string requestMethod); | ||
10 | } | ||
11 | } | 8 | } |