diff options
author | lbsa71 | 2007-03-29 19:05:34 +0000 |
---|---|---|
committer | lbsa71 | 2007-03-29 19:05:34 +0000 |
commit | 514a3230563e19708588945f90e81760377f1265 (patch) | |
tree | 89c2b0c9d05b10b4a470bc9834cc7f4aef89047a /Servers/BaseHttpServer.cs | |
parent | * Tried to make the sandbox/useraccount sim setup a bit simpler (diff) | |
download | opensim-SC-514a3230563e19708588945f90e81760377f1265.zip opensim-SC-514a3230563e19708588945f90e81760377f1265.tar.gz opensim-SC-514a3230563e19708588945f90e81760377f1265.tar.bz2 opensim-SC-514a3230563e19708588945f90e81760377f1265.tar.xz |
* RestMethod now uses same pattern as XmlRpcMethod
* Made /Admin use RestMethod
* HttpServer is now a mini-webapp-server yay!
Diffstat (limited to 'Servers/BaseHttpServer.cs')
-rw-r--r-- | Servers/BaseHttpServer.cs | 37 |
1 files changed, 19 insertions, 18 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) |