diff options
Diffstat (limited to 'OpenSim/Framework/Servers/BaseHttpServer.cs')
-rw-r--r-- | OpenSim/Framework/Servers/BaseHttpServer.cs | 63 |
1 files changed, 22 insertions, 41 deletions
diff --git a/OpenSim/Framework/Servers/BaseHttpServer.cs b/OpenSim/Framework/Servers/BaseHttpServer.cs index 8fa577c..9831108 100644 --- a/OpenSim/Framework/Servers/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/BaseHttpServer.cs | |||
@@ -40,27 +40,6 @@ namespace OpenSim.Framework.Servers | |||
40 | { | 40 | { |
41 | public class BaseHttpServer | 41 | public class BaseHttpServer |
42 | { | 42 | { |
43 | protected class RestMethodEntry | ||
44 | { | ||
45 | private string m_path; | ||
46 | public string Path | ||
47 | { | ||
48 | get { return m_path; } | ||
49 | } | ||
50 | |||
51 | private RestMethod m_restMethod; | ||
52 | public RestMethod RestMethod | ||
53 | { | ||
54 | get { return m_restMethod; } | ||
55 | } | ||
56 | |||
57 | public RestMethodEntry(string path, RestMethod restMethod) | ||
58 | { | ||
59 | m_path = path; | ||
60 | m_restMethod = restMethod; | ||
61 | } | ||
62 | } | ||
63 | |||
64 | protected Thread m_workerThread; | 43 | protected Thread m_workerThread; |
65 | protected HttpListener m_httpListener; | 44 | protected HttpListener m_httpListener; |
66 | protected Dictionary<string, RestMethodEntry> m_restHandlers = new Dictionary<string, RestMethodEntry>(); | 45 | protected Dictionary<string, RestMethodEntry> m_restHandlers = new Dictionary<string, RestMethodEntry>(); |
@@ -74,9 +53,10 @@ namespace OpenSim.Framework.Servers | |||
74 | m_port = port; | 53 | m_port = port; |
75 | } | 54 | } |
76 | 55 | ||
77 | private void AddStreamHandler(string path, IStreamHandler handler) | 56 | public void AddStreamHandler( string path, IStreamHandler handler) |
78 | { | 57 | { |
79 | m_streamHandlers.Add(path, handler); | 58 | string handlerKey = handler.HttpMethod + ":" + path; |
59 | m_streamHandlers.Add(handlerKey, handler); | ||
80 | } | 60 | } |
81 | 61 | ||
82 | public bool AddRestHandler(string method, string path, RestMethod handler) | 62 | public bool AddRestHandler(string method, string path, RestMethod handler) |
@@ -179,18 +159,12 @@ namespace OpenSim.Framework.Servers | |||
179 | { | 159 | { |
180 | string responseString = String.Empty; | 160 | string responseString = String.Empty; |
181 | 161 | ||
182 | try | 162 | XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody); |
183 | { | ||
184 | XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody); | ||
185 | 163 | ||
186 | string methodName = request.MethodName; | 164 | string methodName = request.MethodName; |
165 | |||
166 | responseString = ProcessXMLRPCMethod(methodName, request); | ||
187 | 167 | ||
188 | responseString = ProcessXMLRPCMethod(methodName, request); | ||
189 | } | ||
190 | catch | ||
191 | { | ||
192 | //Console.WriteLine(e.ToString()); | ||
193 | } | ||
194 | return responseString; | 168 | return responseString; |
195 | } | 169 | } |
196 | 170 | ||
@@ -205,12 +179,19 @@ namespace OpenSim.Framework.Servers | |||
205 | response.SendChunked = false; | 179 | response.SendChunked = false; |
206 | 180 | ||
207 | string path = request.RawUrl; | 181 | string path = request.RawUrl; |
182 | string handlerKey = request.HttpMethod + ":" + path; | ||
208 | 183 | ||
209 | IStreamHandler streamHandler; | 184 | IStreamHandler streamHandler; |
210 | 185 | ||
211 | if(TryGetStreamHandler(path, out streamHandler)) | 186 | if (TryGetStreamHandler( handlerKey, out streamHandler)) |
212 | { | 187 | { |
213 | streamHandler.Handle(path, request.InputStream, response.OutputStream ); | 188 | byte[] buffer = streamHandler.Handle(path, request.InputStream ); |
189 | request.InputStream.Close(); | ||
190 | |||
191 | response.ContentType = streamHandler.ContentType; | ||
192 | response.ContentLength64 = buffer.LongLength; | ||
193 | response.OutputStream.Write(buffer, 0, buffer.Length); | ||
194 | response.OutputStream.Close(); | ||
214 | } | 195 | } |
215 | else | 196 | else |
216 | { | 197 | { |
@@ -218,22 +199,22 @@ namespace OpenSim.Framework.Servers | |||
218 | } | 199 | } |
219 | } | 200 | } |
220 | 201 | ||
221 | private bool TryGetStreamHandler(string path, out IStreamHandler streamHandler ) | 202 | private bool TryGetStreamHandler(string handlerKey, out IStreamHandler streamHandler) |
222 | { | 203 | { |
223 | string bestMatch = null; | 204 | string bestMatch = null; |
224 | 205 | ||
225 | foreach (string pattern in m_streamHandlers.Keys) | 206 | foreach (string pattern in m_streamHandlers.Keys) |
226 | { | 207 | { |
227 | if (path.StartsWith(pattern)) | 208 | if (handlerKey.StartsWith(pattern)) |
228 | { | 209 | { |
229 | if (String.IsNullOrEmpty( bestMatch ) || pattern.Length > bestMatch.Length) | 210 | if (String.IsNullOrEmpty(bestMatch) || pattern.Length > bestMatch.Length) |
230 | { | 211 | { |
231 | bestMatch = pattern; | 212 | bestMatch = pattern; |
232 | } | 213 | } |
233 | } | 214 | } |
234 | } | 215 | } |
235 | 216 | ||
236 | if( String.IsNullOrEmpty( bestMatch ) ) | 217 | if (String.IsNullOrEmpty(bestMatch)) |
237 | { | 218 | { |
238 | streamHandler = null; | 219 | streamHandler = null; |
239 | return false; | 220 | return false; |