aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
diff options
context:
space:
mode:
authorMelanie2009-10-02 08:23:38 +0100
committerMelanie2009-10-02 08:23:38 +0100
commit31d8cec0f8cd47ff445edc7771e5e73825a57927 (patch)
treea2d60604317739fa530502c40ffc71bab2a5c494 /OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
parentRestore the missing image handling to the image manager. The missing (diff)
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC-31d8cec0f8cd47ff445edc7771e5e73825a57927.zip
opensim-SC-31d8cec0f8cd47ff445edc7771e5e73825a57927.tar.gz
opensim-SC-31d8cec0f8cd47ff445edc7771e5e73825a57927.tar.bz2
opensim-SC-31d8cec0f8cd47ff445edc7771e5e73825a57927.tar.xz
Merge branch 'master' into diva-textures
Diffstat (limited to 'OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs')
-rw-r--r--OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs112
1 files changed, 63 insertions, 49 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
index 771ae05..6c63c6c 100644
--- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
+++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
@@ -110,7 +110,7 @@ namespace OpenSim.Framework.Servers.HttpServer
110 110
111 public BaseHttpServer(uint port, bool ssl) : this (port) 111 public BaseHttpServer(uint port, bool ssl) : this (port)
112 { 112 {
113 m_ssl = ssl; 113 m_ssl = ssl;
114 } 114 }
115 115
116 public BaseHttpServer(uint port, bool ssl, uint sslport, string CN) : this (port, ssl) 116 public BaseHttpServer(uint port, bool ssl, uint sslport, string CN) : this (port, ssl)
@@ -156,7 +156,7 @@ namespace OpenSim.Framework.Servers.HttpServer
156 lock (m_rpcHandlers) 156 lock (m_rpcHandlers)
157 { 157 {
158 m_rpcHandlers[method] = handler; 158 m_rpcHandlers[method] = handler;
159 m_rpcHandlersKeepAlive[method] = keepAlive; // default 159 m_rpcHandlersKeepAlive[method] = keepAlive; // default
160 } 160 }
161 161
162 return true; 162 return true;
@@ -256,13 +256,51 @@ namespace OpenSim.Framework.Servers.HttpServer
256 IHttpClientContext context = (IHttpClientContext)source; 256 IHttpClientContext context = (IHttpClientContext)source;
257 IHttpRequest request = args.Request; 257 IHttpRequest request = args.Request;
258 258
259
260 PollServiceEventArgs psEvArgs; 259 PollServiceEventArgs psEvArgs;
260
261 if (TryGetPollServiceHTTPHandler(request.UriPath.ToString(), out psEvArgs)) 261 if (TryGetPollServiceHTTPHandler(request.UriPath.ToString(), out psEvArgs))
262 { 262 {
263 263 PollServiceHttpRequest psreq = new PollServiceHttpRequest(psEvArgs, context, request);
264 m_PollServiceManager.Enqueue(new PollServiceHttpRequest(psEvArgs, context, request)); 264
265 //DoHTTPGruntWork(psEvArgs.NoEvents(),new OSHttpResponse(new HttpResponse(context, request))); 265 if (psEvArgs.Request != null)
266 {
267 OSHttpRequest req = new OSHttpRequest(context, request);
268
269 Stream requestStream = req.InputStream;
270
271 Encoding encoding = Encoding.UTF8;
272 StreamReader reader = new StreamReader(requestStream, encoding);
273
274 string requestBody = reader.ReadToEnd();
275
276 Hashtable keysvals = new Hashtable();
277 Hashtable headervals = new Hashtable();
278
279 string[] querystringkeys = req.QueryString.AllKeys;
280 string[] rHeaders = req.Headers.AllKeys;
281
282 keysvals.Add("body", requestBody);
283 keysvals.Add("uri", req.RawUrl);
284 keysvals.Add("content-type", req.ContentType);
285 keysvals.Add("http-method", req.HttpMethod);
286
287 foreach (string queryname in querystringkeys)
288 {
289 keysvals.Add(queryname, req.QueryString[queryname]);
290 }
291
292 foreach (string headername in rHeaders)
293 {
294 headervals[headername] = req.Headers[headername];
295 }
296
297 keysvals.Add("headers",headervals);
298 keysvals.Add("querystringkeys", querystringkeys);
299
300 psEvArgs.Request(psreq.RequestID, keysvals);
301 }
302
303 m_PollServiceManager.Enqueue(psreq);
266 } 304 }
267 else 305 else
268 { 306 {
@@ -275,49 +313,17 @@ namespace OpenSim.Framework.Servers.HttpServer
275 { 313 {
276 OSHttpRequest req = new OSHttpRequest(context, request); 314 OSHttpRequest req = new OSHttpRequest(context, request);
277 OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context); 315 OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context);
278 //resp.KeepAlive = req.KeepAlive;
279 //m_log.Info("[Debug BASE HTTP SERVER]: Got Request");
280 //HttpServerContextObj objstate= new HttpServerContextObj(req,resp);
281 //ThreadPool.QueueUserWorkItem(new WaitCallback(ConvertIHttpClientContextToOSHttp), (object)objstate);
282 HandleRequest(req, resp); 316 HandleRequest(req, resp);
283 } 317 }
284 318
285 public void ConvertIHttpClientContextToOSHttp(object stateinfo) 319 public void ConvertIHttpClientContextToOSHttp(object stateinfo)
286 { 320 {
287 HttpServerContextObj objstate = (HttpServerContextObj)stateinfo; 321 HttpServerContextObj objstate = (HttpServerContextObj)stateinfo;
288 //OSHttpRequest request = new OSHttpRequest(objstate.context,objstate.req);
289 //OSHttpResponse resp = new OSHttpResponse(new HttpServer.HttpResponse(objstate.context, objstate.req));
290 322
291 OSHttpRequest request = objstate.oreq; 323 OSHttpRequest request = objstate.oreq;
292 OSHttpResponse resp = objstate.oresp; 324 OSHttpResponse resp = objstate.oresp;
293 //OSHttpResponse resp = new OSHttpResponse(new HttpServer.HttpResponse(objstate.context, objstate.req));
294 325
295 /* 326 HandleRequest(request,resp);
296 request.AcceptTypes = objstate.req.AcceptTypes;
297 request.ContentLength = (long)objstate.req.ContentLength;
298 request.Headers = objstate.req.Headers;
299 request.HttpMethod = objstate.req.Method;
300 request.InputStream = objstate.req.Body;
301 foreach (string str in request.Headers)
302 {
303 if (str.ToLower().Contains("content-type: "))
304 {
305 request.ContentType = str.Substring(13, str.Length - 13);
306 break;
307 }
308 }
309 //request.KeepAlive = objstate.req.
310 foreach (HttpServer.HttpInput httpinput in objstate.req.QueryString)
311 {
312 request.QueryString.Add(httpinput.Name, httpinput[httpinput.Name]);
313 }
314
315 //request.Query = objstate.req.//objstate.req.QueryString;
316 //foreach (
317 //request.QueryString = objstate.req.QueryString;
318
319 */
320 HandleRequest(request,resp);
321 } 327 }
322 328
323 public virtual void HandleRequest(OSHttpRequest request, OSHttpResponse response) 329 public virtual void HandleRequest(OSHttpRequest request, OSHttpResponse response)
@@ -332,6 +338,7 @@ namespace OpenSim.Framework.Servers.HttpServer
332 // probability event; if a request is matched it is normally expected to be 338 // probability event; if a request is matched it is normally expected to be
333 // handled 339 // handled
334 //m_log.Debug("[BASE HTTP SERVER]: Handling Request" + request.RawUrl); 340 //m_log.Debug("[BASE HTTP SERVER]: Handling Request" + request.RawUrl);
341
335 IHttpAgentHandler agentHandler; 342 IHttpAgentHandler agentHandler;
336 343
337 if (TryGetAgentHandler(request, response, out agentHandler)) 344 if (TryGetAgentHandler(request, response, out agentHandler))
@@ -342,10 +349,11 @@ namespace OpenSim.Framework.Servers.HttpServer
342 } 349 }
343 } 350 }
344 351
345 IRequestHandler requestHandler;
346 //response.KeepAlive = true; 352 //response.KeepAlive = true;
347 response.SendChunked = false; 353 response.SendChunked = false;
348 354
355 IRequestHandler requestHandler;
356
349 string path = request.RawUrl; 357 string path = request.RawUrl;
350 string handlerKey = GetHandlerKey(request.HttpMethod, path); 358 string handlerKey = GetHandlerKey(request.HttpMethod, path);
351 359
@@ -359,6 +367,7 @@ namespace OpenSim.Framework.Servers.HttpServer
359 367
360 response.ContentType = requestHandler.ContentType; // Lets do this defaulting before in case handler has varying content type. 368 response.ContentType = requestHandler.ContentType; // Lets do this defaulting before in case handler has varying content type.
361 369
370
362 if (requestHandler is IStreamedRequestHandler) 371 if (requestHandler is IStreamedRequestHandler)
363 { 372 {
364 IStreamedRequestHandler streamedRequestHandler = requestHandler as IStreamedRequestHandler; 373 IStreamedRequestHandler streamedRequestHandler = requestHandler as IStreamedRequestHandler;
@@ -404,6 +413,7 @@ namespace OpenSim.Framework.Servers.HttpServer
404 // } 413 // }
405 414
406 keysvals.Add("requestbody", requestBody); 415 keysvals.Add("requestbody", requestBody);
416 keysvals.Add("headers",headervals);
407 if (keysvals.Contains("method")) 417 if (keysvals.Contains("method"))
408 { 418 {
409 //m_log.Warn("[HTTP]: Contains Method"); 419 //m_log.Warn("[HTTP]: Contains Method");
@@ -702,7 +712,7 @@ namespace OpenSim.Framework.Servers.HttpServer
702 lock (m_rpcHandlers) 712 lock (m_rpcHandlers)
703 { 713 {
704 methodWasFound = m_rpcHandlers.TryGetValue(methodName, out method); 714 methodWasFound = m_rpcHandlers.TryGetValue(methodName, out method);
705 } 715 }
706 716
707 if (methodWasFound) 717 if (methodWasFound)
708 { 718 {
@@ -726,8 +736,11 @@ namespace OpenSim.Framework.Servers.HttpServer
726 else 736 else
727 { 737 {
728 xmlRpcResponse = new XmlRpcResponse(); 738 xmlRpcResponse = new XmlRpcResponse();
739
729 // Code set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php 740 // Code set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
730 xmlRpcResponse.SetFault(-32601, String.Format("Requested method [{0}] not found", methodName)); 741 xmlRpcResponse.SetFault(
742 XmlRpcErrorCodes.SERVER_ERROR_METHOD,
743 String.Format("Requested method [{0}] not found", methodName));
731 } 744 }
732 745
733 responseString = XmlRpcResponseSerializer.Singleton.Serialize(xmlRpcResponse); 746 responseString = XmlRpcResponseSerializer.Singleton.Serialize(xmlRpcResponse);
@@ -747,6 +760,7 @@ namespace OpenSim.Framework.Servers.HttpServer
747 response.SendChunked = false; 760 response.SendChunked = false;
748 response.ContentLength64 = buf.Length; 761 response.ContentLength64 = buf.Length;
749 response.ContentEncoding = Encoding.UTF8; 762 response.ContentEncoding = Encoding.UTF8;
763
750 try 764 try
751 { 765 {
752 response.OutputStream.Write(buf, 0, buf.Length); 766 response.OutputStream.Write(buf, 0, buf.Length);
@@ -917,7 +931,7 @@ namespace OpenSim.Framework.Servers.HttpServer
917 } 931 }
918 catch (IOException e) 932 catch (IOException e)
919 { 933 {
920 m_log.DebugFormat("[BASE HTTP SERVER] LLSD IOException {0}.", e); 934 m_log.DebugFormat("[BASE HTTP SERVER] LLSD IOException {0}.", e);
921 } 935 }
922 catch (SocketException e) 936 catch (SocketException e)
923 { 937 {
@@ -1354,7 +1368,7 @@ namespace OpenSim.Framework.Servers.HttpServer
1354 bestMatch = pattern; 1368 bestMatch = pattern;
1355 } 1369 }
1356 } 1370 }
1357 } 1371 }
1358 1372
1359 if (String.IsNullOrEmpty(bestMatch)) 1373 if (String.IsNullOrEmpty(bestMatch))
1360 { 1374 {
@@ -1466,7 +1480,7 @@ namespace OpenSim.Framework.Servers.HttpServer
1466 { 1480 {
1467 m_log.Warn("[BASE HTTP SERVER] XmlRpcRequest issue: " + e.Message); 1481 m_log.Warn("[BASE HTTP SERVER] XmlRpcRequest issue: " + e.Message);
1468 } 1482 }
1469 } 1483 }
1470 } 1484 }
1471 1485
1472 public void SendHTML404(OSHttpResponse response, string host) 1486 public void SendHTML404(OSHttpResponse response, string host)
@@ -1575,7 +1589,7 @@ namespace OpenSim.Framework.Servers.HttpServer
1575 // if you want more detailed trace information from the HttpServer 1589 // if you want more detailed trace information from the HttpServer
1576 //m_httpListener2.UseTraceLogs = true; 1590 //m_httpListener2.UseTraceLogs = true;
1577 1591
1578 //m_httpListener2.DisconnectHandler = httpServerDisconnectMonitor; 1592 //m_httpListener2.DisconnectHandler = httpServerDisconnectMonitor;
1579 } 1593 }
1580 else 1594 else
1581 { 1595 {
@@ -1610,7 +1624,7 @@ namespace OpenSim.Framework.Servers.HttpServer
1610 } 1624 }
1611 1625
1612 public void httpServerDisconnectMonitor(IHttpClientContext source, SocketError err) 1626 public void httpServerDisconnectMonitor(IHttpClientContext source, SocketError err)
1613 { 1627 {
1614 switch (err) 1628 switch (err)
1615 { 1629 {
1616 case SocketError.NotSocket: 1630 case SocketError.NotSocket:
@@ -1621,7 +1635,7 @@ namespace OpenSim.Framework.Servers.HttpServer
1621 } 1635 }
1622 1636
1623 public void httpServerException(object source, Exception exception) 1637 public void httpServerException(object source, Exception exception)
1624 { 1638 {
1625 m_log.ErrorFormat("[HTTPSERVER]: {0} had an exception {1}", source.ToString(), exception.ToString()); 1639 m_log.ErrorFormat("[HTTPSERVER]: {0} had an exception {1}", source.ToString(), exception.ToString());
1626 /* 1640 /*
1627 if (HTTPDRunning)// && NotSocketErrors > 5) 1641 if (HTTPDRunning)// && NotSocketErrors > 5)
@@ -1648,7 +1662,7 @@ namespace OpenSim.Framework.Servers.HttpServer
1648 } 1662 }
1649 catch (NullReferenceException) 1663 catch (NullReferenceException)
1650 { 1664 {
1651 m_log.Warn("[BASEHTTPSERVER]: Null Reference when stopping HttpServer."); 1665 m_log.Warn("[BASEHTTPSERVER]: Null Reference when stopping HttpServer.");
1652 } 1666 }
1653 1667
1654 } 1668 }