diff options
author | Dr Scofield | 2008-07-14 12:18:32 +0000 |
---|---|---|
committer | Dr Scofield | 2008-07-14 12:18:32 +0000 |
commit | 7692f3e18f49fc57b63efbe54b7ac71de2fb7e16 (patch) | |
tree | 4ee9a4279ff904a8c5fc7e2bd9f85f55bf8b52ba /OpenSim/Framework/Servers/OSHttpRequestPump.cs | |
parent | adds a default value of true to the new IRC bridge configuration option "nick... (diff) | |
download | opensim-SC_OLD-7692f3e18f49fc57b63efbe54b7ac71de2fb7e16.zip opensim-SC_OLD-7692f3e18f49fc57b63efbe54b7ac71de2fb7e16.tar.gz opensim-SC_OLD-7692f3e18f49fc57b63efbe54b7ac71de2fb7e16.tar.bz2 opensim-SC_OLD-7692f3e18f49fc57b63efbe54b7ac71de2fb7e16.tar.xz |
further work in progress on the HttpServer side: XmlRpc handler path
almost complete and soon to be ready for testing; OSHttpResponse code
out.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Servers/OSHttpRequestPump.cs | 80 |
1 files changed, 57 insertions, 23 deletions
diff --git a/OpenSim/Framework/Servers/OSHttpRequestPump.cs b/OpenSim/Framework/Servers/OSHttpRequestPump.cs index 4218be5..56714fa 100644 --- a/OpenSim/Framework/Servers/OSHttpRequestPump.cs +++ b/OpenSim/Framework/Servers/OSHttpRequestPump.cs | |||
@@ -28,6 +28,7 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Collections.Specialized; | 30 | using System.Collections.Specialized; |
31 | using System.IO; | ||
31 | using System.Net; | 32 | using System.Net; |
32 | using System.Reflection; | 33 | using System.Reflection; |
33 | using System.Text.RegularExpressions; | 34 | using System.Text.RegularExpressions; |
@@ -114,7 +115,7 @@ namespace OpenSim.Framework.Servers | |||
114 | 115 | ||
115 | // process req: we try each handler in turn until | 116 | // process req: we try each handler in turn until |
116 | // we are either out of handlers or get back a | 117 | // we are either out of handlers or get back a |
117 | // Handled or Detached | 118 | // Pass or Done |
118 | OSHttpHandlerResult rc = OSHttpHandlerResult.Unprocessed; | 119 | OSHttpHandlerResult rc = OSHttpHandlerResult.Unprocessed; |
119 | foreach (OSHttpHandler h in handlers) | 120 | foreach (OSHttpHandler h in handlers) |
120 | { | 121 | { |
@@ -123,22 +124,35 @@ namespace OpenSim.Framework.Servers | |||
123 | // Pass: handler did not process the request, | 124 | // Pass: handler did not process the request, |
124 | // try next handler | 125 | // try next handler |
125 | if (OSHttpHandlerResult.Pass == rc) continue; | 126 | if (OSHttpHandlerResult.Pass == rc) continue; |
126 | // Detached: handler is taking over processing | 127 | |
127 | // of request, we are done | 128 | // Handled: handler has processed the request |
128 | if (OSHttpHandlerResult.Detached == rc) break; | 129 | if (OSHttpHandlerResult.Done == rc) break; |
129 | |||
130 | if (OSHttpHandlerResult.Handled != rc) | ||
131 | { | ||
132 | // something went wrong | ||
133 | throw new Exception(String.Format("[{0}] got unexpected OSHttpHandlerResult {1}", EngineID, rc)); | ||
134 | } | ||
135 | 130 | ||
136 | // Handled: clean up now | 131 | // hmm, something went wrong |
137 | req.HttpRequest.AddHeader("keep-alive", "false"); | 132 | throw new Exception(String.Format("[{0}] got unexpected OSHttpHandlerResult {1}", EngineID, rc)); |
133 | } | ||
134 | |||
135 | if (OSHttpHandlerResult.Unprocessed == rc) | ||
136 | { | ||
137 | _log.InfoFormat("[{0}] OSHttpHandler: no handler registered for {1}", EngineID, req); | ||
138 | |||
139 | // set up response header | ||
140 | OSHttpResponse resp = new OSHttpResponse(req); | ||
141 | resp.StatusCode = (int)OSHttpStatusCode.ClientErrorNotFound; | ||
142 | resp.StatusDescription = String.Format("no handler on call for {0}", req); | ||
143 | resp.ContentType = "text/html"; | ||
144 | |||
145 | // add explanatory message | ||
146 | StreamWriter body = new StreamWriter(resp.Body); | ||
147 | body.WriteLine("<html>"); | ||
148 | body.WriteLine("<header><title>Ooops...</title><header>"); | ||
149 | body.WriteLine(String.Format("<body><p>{0}</p></body>", resp.StatusDescription)); | ||
150 | body.WriteLine("</html>"); | ||
151 | body.Flush(); | ||
138 | 152 | ||
139 | break; | 153 | // and ship it back |
154 | resp.HttpResponse.Send(); | ||
140 | } | 155 | } |
141 | |||
142 | } | 156 | } |
143 | catch (Exception e) | 157 | catch (Exception e) |
144 | { | 158 | { |
@@ -199,17 +213,37 @@ namespace OpenSim.Framework.Servers | |||
199 | NameValueCollection headers = req.HttpRequest.Headers; | 213 | NameValueCollection headers = req.HttpRequest.Headers; |
200 | foreach (string tag in headerRegexs.Keys) | 214 | foreach (string tag in headerRegexs.Keys) |
201 | { | 215 | { |
202 | if (null != headers[tag]) | 216 | // do we have a header "tag"? |
217 | if (null == headers[tag]) | ||
203 | { | 218 | { |
204 | Match hm = headerRegexs[tag].Match(headers[tag]); | 219 | // no: remove the handler if it was added |
205 | if (hm.Success) { | 220 | // earlier and on to the next one |
206 | headersMatch++; | 221 | scoredHandlers.Remove(h); |
207 | continue; | 222 | break; |
208 | } | ||
209 | } | 223 | } |
210 | 224 | ||
211 | scoredHandlers.Remove(h); | 225 | // does the content of header "tag" match |
212 | break; | 226 | // the supplied regex? |
227 | Match hm = headerRegexs[tag].Match(headers[tag]); | ||
228 | if (!hm.Success) { | ||
229 | // no: remove the handler if it was added | ||
230 | // earlier and on to the next one | ||
231 | scoredHandlers.Remove(h); | ||
232 | break; | ||
233 | } | ||
234 | |||
235 | // if we are looking at the "content-type" tag, | ||
236 | // check wether h has a ContentTypeChecker and | ||
237 | // invoke it if it has | ||
238 | if ((null != h.ContentTypeChecker) && !h.ContentTypeChecker(req)) | ||
239 | { | ||
240 | scoredHandlers.Remove(h); | ||
241 | break; | ||
242 | } | ||
243 | |||
244 | // ok: header matches | ||
245 | headersMatch++; | ||
246 | continue; | ||
213 | } | 247 | } |
214 | // check whether h got kicked out | 248 | // check whether h got kicked out |
215 | if (!scoredHandlers.ContainsKey(h)) continue; | 249 | if (!scoredHandlers.ContainsKey(h)) continue; |