aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/OSHttpRequestPump.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Servers/OSHttpRequestPump.cs')
-rw-r--r--OpenSim/Framework/Servers/OSHttpRequestPump.cs80
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 @@
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Collections.Specialized; 30using System.Collections.Specialized;
31using System.IO;
31using System.Net; 32using System.Net;
32using System.Reflection; 33using System.Reflection;
33using System.Text.RegularExpressions; 34using 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;