aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/BaseHttpServer.cs
diff options
context:
space:
mode:
authorlbsa712007-07-04 14:12:32 +0000
committerlbsa712007-07-04 14:12:32 +0000
commit6a2588454a1ac4bb484ad0b9ee648e9ac156f8db (patch)
treefd4e0d33f65e36365d15d991f95d323e6d15e8b1 /OpenSim/Framework/Servers/BaseHttpServer.cs
parent* Added StreamHandler support (diff)
downloadopensim-SC_OLD-6a2588454a1ac4bb484ad0b9ee648e9ac156f8db.zip
opensim-SC_OLD-6a2588454a1ac4bb484ad0b9ee648e9ac156f8db.tar.gz
opensim-SC_OLD-6a2588454a1ac4bb484ad0b9ee648e9ac156f8db.tar.bz2
opensim-SC_OLD-6a2588454a1ac4bb484ad0b9ee648e9ac156f8db.tar.xz
* Removed AssetHttpServer, using BaseHttpServer instead
* Removed legacy REST handling * Created two custom IStreamHandlers for asset up/download * Removed quite a lot of double and triple encodings, trying to work towards binary only and direct write into storage. * Introduced BaseStreamHandler with GetParam() and some other goodies
Diffstat (limited to 'OpenSim/Framework/Servers/BaseHttpServer.cs')
-rw-r--r--OpenSim/Framework/Servers/BaseHttpServer.cs163
1 files changed, 88 insertions, 75 deletions
diff --git a/OpenSim/Framework/Servers/BaseHttpServer.cs b/OpenSim/Framework/Servers/BaseHttpServer.cs
index 9831108..aed538b 100644
--- a/OpenSim/Framework/Servers/BaseHttpServer.cs
+++ b/OpenSim/Framework/Servers/BaseHttpServer.cs
@@ -42,48 +42,56 @@ namespace OpenSim.Framework.Servers
42 { 42 {
43 protected Thread m_workerThread; 43 protected Thread m_workerThread;
44 protected HttpListener m_httpListener; 44 protected HttpListener m_httpListener;
45 protected Dictionary<string, RestMethodEntry> m_restHandlers = new Dictionary<string, RestMethodEntry>(); 45 //protected Dictionary<string, RestMethodEntry> m_restHandlers = new Dictionary<string, RestMethodEntry>();
46 protected Dictionary<string, XmlRpcMethod> m_rpcHandlers = new Dictionary<string, XmlRpcMethod>(); 46 protected Dictionary<string, XmlRpcMethod> m_rpcHandlers = new Dictionary<string, XmlRpcMethod>();
47 protected Dictionary<string, IStreamHandler> m_streamHandlers = new Dictionary<string, IStreamHandler>(); 47 protected Dictionary<string, IStreamHandler> m_streamHandlers = new Dictionary<string, IStreamHandler>();
48 protected int m_port; 48 protected int m_port;
49 protected bool firstcaps = true; 49 protected bool m_firstcaps = true;
50 50
51 public BaseHttpServer(int port) 51 public BaseHttpServer(int port)
52 { 52 {
53 m_port = port; 53 m_port = port;
54 } 54 }
55 55
56 public void AddStreamHandler( string path, IStreamHandler handler) 56 public void AddStreamHandler( IStreamHandler handler)
57 { 57 {
58 string handlerKey = handler.HttpMethod + ":" + path; 58 string httpMethod = handler.HttpMethod;
59 string path = handler.Path;
60
61 string handlerKey = GetHandlerKey(httpMethod, path);
59 m_streamHandlers.Add(handlerKey, handler); 62 m_streamHandlers.Add(handlerKey, handler);
60 } 63 }
61 64
62 public bool AddRestHandler(string method, string path, RestMethod handler) 65 private static string GetHandlerKey(string httpMethod, string path)
63 { 66 {
64 //Console.WriteLine("adding new REST handler for path " + path); 67 return httpMethod + ":" + path;
65 string methodKey = String.Format("{0}: {1}", method, path);
66
67 if (!this.m_restHandlers.ContainsKey(methodKey))
68 {
69 this.m_restHandlers.Add(methodKey, new RestMethodEntry(path, handler));
70 return true;
71 }
72
73 //must already have a handler for that path so return false
74 return false;
75 } 68 }
76 69
77 public bool RemoveRestHandler(string method, string path) 70 //public bool AddRestHandler(string method, string path, RestMethod handler)
78 { 71 //{
79 string methodKey = String.Format("{0}: {1}", method, path); 72 // //Console.WriteLine("adding new REST handler for path " + path);
80 if (this.m_restHandlers.ContainsKey(methodKey)) 73 // string methodKey = String.Format("{0}: {1}", method, path);
81 { 74
82 this.m_restHandlers.Remove(methodKey); 75 // if (!this.m_restHandlers.ContainsKey(methodKey))
83 return true; 76 // {
84 } 77 // this.m_restHandlers.Add(methodKey, new RestMethodEntry(path, handler));
85 return false; 78 // return true;
86 } 79 // }
80
81 // //must already have a handler for that path so return false
82 // return false;
83 //}
84
85 //public bool RemoveRestHandler(string method, string path)
86 //{
87 // string methodKey = String.Format("{0}: {1}", method, path);
88 // if (this.m_restHandlers.ContainsKey(methodKey))
89 // {
90 // this.m_restHandlers.Remove(methodKey);
91 // return true;
92 // }
93 // return false;
94 //}
87 95
88 public bool AddXmlRPCHandler(string method, XmlRpcMethod handler) 96 public bool AddXmlRPCHandler(string method, XmlRpcMethod handler)
89 { 97 {
@@ -119,40 +127,40 @@ namespace OpenSim.Framework.Servers
119 return XmlRpcResponseSerializer.Singleton.Serialize(response); 127 return XmlRpcResponseSerializer.Singleton.Serialize(response);
120 } 128 }
121 129
122 protected virtual string ParseREST(string request, string path, string method) 130 //protected virtual string ParseREST(string request, string path, string method)
123 { 131 //{
124 string response; 132 // string response;
125 133
126 string requestKey = String.Format("{0}: {1}", method, path); 134 // string requestKey = String.Format("{0}: {1}", method, path);
127 135
128 string bestMatch = String.Empty; 136 // string bestMatch = String.Empty;
129 foreach (string currentKey in m_restHandlers.Keys) 137 // foreach (string currentKey in m_restHandlers.Keys)
130 { 138 // {
131 if (requestKey.StartsWith(currentKey)) 139 // if (requestKey.StartsWith(currentKey))
132 { 140 // {
133 if (currentKey.Length > bestMatch.Length) 141 // if (currentKey.Length > bestMatch.Length)
134 { 142 // {
135 bestMatch = currentKey; 143 // bestMatch = currentKey;
136 } 144 // }
137 } 145 // }
138 } 146 // }
139 147
140 RestMethodEntry restMethodEntry; 148 // RestMethodEntry restMethodEntry;
141 if (m_restHandlers.TryGetValue(bestMatch, out restMethodEntry)) 149 // if (m_restHandlers.TryGetValue(bestMatch, out restMethodEntry))
142 { 150 // {
143 RestMethod restMethod = restMethodEntry.RestMethod; 151 // RestMethod restMethod = restMethodEntry.RestMethod;
144 152
145 string param = path.Substring(restMethodEntry.Path.Length); 153 // string param = path.Substring(restMethodEntry.Path.Length);
146 response = restMethod(request, path, param); 154 // response = restMethod(request, path, param);
147 155
148 } 156 // }
149 else 157 // else
150 { 158 // {
151 response = String.Empty; 159 // response = String.Empty;
152 } 160 // }
153 161
154 return response; 162 // return response;
155 } 163 //}
156 164
157 165
158 protected virtual string ParseXMLRPC(string requestBody) 166 protected virtual string ParseXMLRPC(string requestBody)
@@ -179,13 +187,13 @@ namespace OpenSim.Framework.Servers
179 response.SendChunked = false; 187 response.SendChunked = false;
180 188
181 string path = request.RawUrl; 189 string path = request.RawUrl;
182 string handlerKey = request.HttpMethod + ":" + path; 190 string handlerKey = GetHandlerKey( request.HttpMethod, path );
183 191
184 IStreamHandler streamHandler; 192 IStreamHandler streamHandler;
185 193
186 if (TryGetStreamHandler( handlerKey, out streamHandler)) 194 if (TryGetStreamHandler( handlerKey, out streamHandler))
187 { 195 {
188 byte[] buffer = streamHandler.Handle(path, request.InputStream ); 196 byte[] buffer = streamHandler.Handle(path, request.InputStream);
189 request.InputStream.Close(); 197 request.InputStream.Close();
190 198
191 response.ContentType = streamHandler.ContentType; 199 response.ContentType = streamHandler.ContentType;
@@ -253,25 +261,25 @@ namespace OpenSim.Framework.Servers
253 response.AddHeader("Content-type", "text/xml"); 261 response.AddHeader("Content-type", "text/xml");
254 break; 262 break;
255 263
256 case "application/xml": 264 //case "application/xml":
257 case "application/octet-stream": 265 //case "application/octet-stream":
258 // probably LLSD we hope, otherwise it should be ignored by the parser 266 // // probably LLSD we hope, otherwise it should be ignored by the parser
259 // responseString = ParseLLSDXML(requestBody); 267 // // responseString = ParseLLSDXML(requestBody);
260 responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); 268 // responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
261 response.AddHeader("Content-type", "application/xml"); 269 // response.AddHeader("Content-type", "application/xml");
262 break; 270 // break;
263 271
264 case "application/x-www-form-urlencoded": 272 //case "application/x-www-form-urlencoded":
265 // a form data POST so send to the REST parser 273 // // a form data POST so send to the REST parser
266 responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); 274 // responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
267 response.AddHeader("Content-type", "text/html"); 275 // response.AddHeader("Content-type", "text/html");
268 break; 276 // break;
269 277
270 case null: 278 //case null:
271 // must be REST or invalid crap, so pass to the REST parser 279 // // must be REST or invalid crap, so pass to the REST parser
272 responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); 280 // responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
273 response.AddHeader("Content-type", "text/html"); 281 // response.AddHeader("Content-type", "text/html");
274 break; 282 // break;
275 283
276 } 284 }
277 285
@@ -318,5 +326,10 @@ namespace OpenSim.Framework.Servers
318 } 326 }
319 } 327 }
320 328
329
330 public void RemoveStreamHandler(string httpMethod, string path)
331 {
332 m_streamHandlers.Remove(GetHandlerKey(httpMethod, path));
333 }
321 } 334 }
322} 335}