diff options
Merge branch 'master' into careminster
Conflicts:
OpenSim/Region/Framework/Scenes/Scene.cs
Diffstat (limited to 'OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs')
-rw-r--r-- | OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 230 |
1 files changed, 135 insertions, 95 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 691b45a..29593e5 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | |||
@@ -54,8 +54,23 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
54 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 54 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
55 | private HttpServerLogWriter httpserverlog = new HttpServerLogWriter(); | 55 | private HttpServerLogWriter httpserverlog = new HttpServerLogWriter(); |
56 | 56 | ||
57 | /// <summary> | ||
58 | /// Gets or sets the debug level. | ||
59 | /// </summary> | ||
60 | /// <value> | ||
61 | /// See MainServer.DebugLevel. | ||
62 | /// </value> | ||
57 | public int DebugLevel { get; set; } | 63 | public int DebugLevel { get; set; } |
58 | 64 | ||
65 | /// <summary> | ||
66 | /// Request number for diagnostic purposes. | ||
67 | /// </summary> | ||
68 | /// <remarks> | ||
69 | /// This is an internal number. In some debug situations an external number may also be supplied in the | ||
70 | /// opensim-request-id header but we are not currently logging this. | ||
71 | /// </remarks> | ||
72 | public int RequestNumber { get; private set; } | ||
73 | |||
59 | private volatile int NotSocketErrors = 0; | 74 | private volatile int NotSocketErrors = 0; |
60 | public volatile bool HTTPDRunning = false; | 75 | public volatile bool HTTPDRunning = false; |
61 | 76 | ||
@@ -67,7 +82,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
67 | protected Dictionary<string, LLSDMethod> m_llsdHandlers = new Dictionary<string, LLSDMethod>(); | 82 | protected Dictionary<string, LLSDMethod> m_llsdHandlers = new Dictionary<string, LLSDMethod>(); |
68 | protected Dictionary<string, IRequestHandler> m_streamHandlers = new Dictionary<string, IRequestHandler>(); | 83 | protected Dictionary<string, IRequestHandler> m_streamHandlers = new Dictionary<string, IRequestHandler>(); |
69 | protected Dictionary<string, GenericHTTPMethod> m_HTTPHandlers = new Dictionary<string, GenericHTTPMethod>(); | 84 | protected Dictionary<string, GenericHTTPMethod> m_HTTPHandlers = new Dictionary<string, GenericHTTPMethod>(); |
70 | protected Dictionary<string, IHttpAgentHandler> m_agentHandlers = new Dictionary<string, IHttpAgentHandler>(); | 85 | // protected Dictionary<string, IHttpAgentHandler> m_agentHandlers = new Dictionary<string, IHttpAgentHandler>(); |
71 | protected Dictionary<string, PollServiceEventArgs> m_pollHandlers = | 86 | protected Dictionary<string, PollServiceEventArgs> m_pollHandlers = |
72 | new Dictionary<string, PollServiceEventArgs>(); | 87 | new Dictionary<string, PollServiceEventArgs>(); |
73 | 88 | ||
@@ -245,29 +260,29 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
245 | return new List<string>(m_pollHandlers.Keys); | 260 | return new List<string>(m_pollHandlers.Keys); |
246 | } | 261 | } |
247 | 262 | ||
248 | // Note that the agent string is provided simply to differentiate | 263 | // // Note that the agent string is provided simply to differentiate |
249 | // the handlers - it is NOT required to be an actual agent header | 264 | // // the handlers - it is NOT required to be an actual agent header |
250 | // value. | 265 | // // value. |
251 | public bool AddAgentHandler(string agent, IHttpAgentHandler handler) | 266 | // public bool AddAgentHandler(string agent, IHttpAgentHandler handler) |
252 | { | 267 | // { |
253 | lock (m_agentHandlers) | 268 | // lock (m_agentHandlers) |
254 | { | 269 | // { |
255 | if (!m_agentHandlers.ContainsKey(agent)) | 270 | // if (!m_agentHandlers.ContainsKey(agent)) |
256 | { | 271 | // { |
257 | m_agentHandlers.Add(agent, handler); | 272 | // m_agentHandlers.Add(agent, handler); |
258 | return true; | 273 | // return true; |
259 | } | 274 | // } |
260 | } | 275 | // } |
261 | 276 | // | |
262 | //must already have a handler for that path so return false | 277 | // //must already have a handler for that path so return false |
263 | return false; | 278 | // return false; |
264 | } | 279 | // } |
265 | 280 | // | |
266 | public List<string> GetAgentHandlerKeys() | 281 | // public List<string> GetAgentHandlerKeys() |
267 | { | 282 | // { |
268 | lock (m_agentHandlers) | 283 | // lock (m_agentHandlers) |
269 | return new List<string>(m_agentHandlers.Keys); | 284 | // return new List<string>(m_agentHandlers.Keys); |
270 | } | 285 | // } |
271 | 286 | ||
272 | public bool AddLLSDHandler(string path, LLSDMethod handler) | 287 | public bool AddLLSDHandler(string path, LLSDMethod handler) |
273 | { | 288 | { |
@@ -296,6 +311,8 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
296 | 311 | ||
297 | private void OnRequest(object source, RequestEventArgs args) | 312 | private void OnRequest(object source, RequestEventArgs args) |
298 | { | 313 | { |
314 | RequestNumber++; | ||
315 | |||
299 | try | 316 | try |
300 | { | 317 | { |
301 | IHttpClientContext context = (IHttpClientContext)source; | 318 | IHttpClientContext context = (IHttpClientContext)source; |
@@ -405,7 +422,6 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
405 | string requestMethod = request.HttpMethod; | 422 | string requestMethod = request.HttpMethod; |
406 | string uriString = request.RawUrl; | 423 | string uriString = request.RawUrl; |
407 | 424 | ||
408 | // string reqnum = "unknown"; | ||
409 | int requestStartTick = Environment.TickCount; | 425 | int requestStartTick = Environment.TickCount; |
410 | 426 | ||
411 | // Will be adjusted later on. | 427 | // Will be adjusted later on. |
@@ -422,22 +438,22 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
422 | 438 | ||
423 | Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", true); | 439 | Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", true); |
424 | 440 | ||
425 | // This is the REST agent interface. We require an agent to properly identify | 441 | // // This is the REST agent interface. We require an agent to properly identify |
426 | // itself. If the REST handler recognizes the prefix it will attempt to | 442 | // // itself. If the REST handler recognizes the prefix it will attempt to |
427 | // satisfy the request. If it is not recognizable, and no damage has occurred | 443 | // // satisfy the request. If it is not recognizable, and no damage has occurred |
428 | // the request can be passed through to the other handlers. This is a low | 444 | // // the request can be passed through to the other handlers. This is a low |
429 | // probability event; if a request is matched it is normally expected to be | 445 | // // probability event; if a request is matched it is normally expected to be |
430 | // handled | 446 | // // handled |
431 | IHttpAgentHandler agentHandler; | 447 | // IHttpAgentHandler agentHandler; |
432 | 448 | // | |
433 | if (TryGetAgentHandler(request, response, out agentHandler)) | 449 | // if (TryGetAgentHandler(request, response, out agentHandler)) |
434 | { | 450 | // { |
435 | if (HandleAgentRequest(agentHandler, request, response)) | 451 | // if (HandleAgentRequest(agentHandler, request, response)) |
436 | { | 452 | // { |
437 | requestEndTick = Environment.TickCount; | 453 | // requestEndTick = Environment.TickCount; |
438 | return; | 454 | // return; |
439 | } | 455 | // } |
440 | } | 456 | // } |
441 | 457 | ||
442 | //response.KeepAlive = true; | 458 | //response.KeepAlive = true; |
443 | response.SendChunked = false; | 459 | response.SendChunked = false; |
@@ -529,8 +545,8 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
529 | 545 | ||
530 | if (DebugLevel >= 3) | 546 | if (DebugLevel >= 3) |
531 | m_log.DebugFormat( | 547 | m_log.DebugFormat( |
532 | "[BASE HTTP SERVER]: Found a {0} content type handler for {1} {2}", | 548 | "[BASE HTTP SERVER]: HTTP IN {0} :{1} {2} content type handler {3} {4} from {5}", |
533 | request.ContentType, request.HttpMethod, request.Url.PathAndQuery); | 549 | RequestNumber, Port, request.ContentType, request.HttpMethod, request.Url.PathAndQuery, request.RemoteIPEndPoint); |
534 | 550 | ||
535 | buffer = HandleHTTPRequest(request, response); | 551 | buffer = HandleHTTPRequest(request, response); |
536 | break; | 552 | break; |
@@ -541,8 +557,8 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
541 | 557 | ||
542 | if (DebugLevel >= 3) | 558 | if (DebugLevel >= 3) |
543 | m_log.DebugFormat( | 559 | m_log.DebugFormat( |
544 | "[BASE HTTP SERVER]: Found a {0} content type handler for {1} {2}", | 560 | "[BASE HTTP SERVER]: HTTP IN {0} :{1} {2} content type handler {3} {4} from {5}", |
545 | request.ContentType, request.HttpMethod, request.Url.PathAndQuery); | 561 | RequestNumber, Port, request.ContentType, request.HttpMethod, request.Url.PathAndQuery, request.RemoteIPEndPoint); |
546 | 562 | ||
547 | buffer = HandleLLSDRequests(request, response); | 563 | buffer = HandleLLSDRequests(request, response); |
548 | break; | 564 | break; |
@@ -620,11 +636,11 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
620 | } | 636 | } |
621 | catch (IOException e) | 637 | catch (IOException e) |
622 | { | 638 | { |
623 | m_log.Error(String.Format("[BASE HTTP SERVER]: HandleRequest() threw {0} ", e.Message), e); | 639 | m_log.Error(String.Format("[BASE HTTP SERVER]: HandleRequest() threw {0} ", e.StackTrace), e); |
624 | } | 640 | } |
625 | catch (Exception e) | 641 | catch (Exception e) |
626 | { | 642 | { |
627 | m_log.Error(String.Format("[BASE HTTP SERVER]: HandleRequest() threw {0} ", e.Message), e); | 643 | m_log.Error(String.Format("[BASE HTTP SERVER]: HandleRequest() threw {0} ", e.StackTrace), e); |
628 | SendHTML500(response); | 644 | SendHTML500(response); |
629 | } | 645 | } |
630 | finally | 646 | finally |
@@ -635,12 +651,21 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
635 | if (tickdiff > 3000 && requestHandler.Name != "GetTexture") | 651 | if (tickdiff > 3000 && requestHandler.Name != "GetTexture") |
636 | { | 652 | { |
637 | m_log.InfoFormat( | 653 | m_log.InfoFormat( |
638 | "[BASE HTTP SERVER]: Slow handling of {0} {1} {2} {3} from {4} took {5}ms", | 654 | "[BASE HTTP SERVER]: Slow handling of {0} {1} {2} {3} {4} from {5} took {6}ms", |
655 | RequestNumber, | ||
639 | requestMethod, | 656 | requestMethod, |
640 | uriString, | 657 | uriString, |
641 | requestHandler != null ? requestHandler.Name : "", | 658 | requestHandler != null ? requestHandler.Name : "", |
642 | requestHandler != null ? requestHandler.Description : "", | 659 | requestHandler != null ? requestHandler.Description : "", |
643 | request.RemoteIPEndPoint.ToString(), | 660 | request.RemoteIPEndPoint, |
661 | tickdiff); | ||
662 | } | ||
663 | else if (DebugLevel >= 4) | ||
664 | { | ||
665 | m_log.DebugFormat( | ||
666 | "[BASE HTTP SERVER]: HTTP IN {0} :{1} took {2}ms", | ||
667 | RequestNumber, | ||
668 | Port, | ||
644 | tickdiff); | 669 | tickdiff); |
645 | } | 670 | } |
646 | } | 671 | } |
@@ -649,30 +674,45 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
649 | private void LogIncomingToStreamHandler(OSHttpRequest request, IRequestHandler requestHandler) | 674 | private void LogIncomingToStreamHandler(OSHttpRequest request, IRequestHandler requestHandler) |
650 | { | 675 | { |
651 | m_log.DebugFormat( | 676 | m_log.DebugFormat( |
652 | "[BASE HTTP SERVER]: Found stream handler for {0} {1} {2} {3}", | 677 | "[BASE HTTP SERVER]: HTTP IN {0} :{1} stream handler {2} {3} {4} {5} from {6}", |
653 | request.HttpMethod, request.Url.PathAndQuery, requestHandler.Name, requestHandler.Description); | 678 | RequestNumber, |
654 | 679 | Port, | |
655 | if (DebugLevel >= 4) | 680 | request.HttpMethod, |
681 | request.Url.PathAndQuery, | ||
682 | requestHandler.Name, | ||
683 | requestHandler.Description, | ||
684 | request.RemoteIPEndPoint); | ||
685 | |||
686 | if (DebugLevel >= 5) | ||
656 | LogIncomingInDetail(request); | 687 | LogIncomingInDetail(request); |
657 | } | 688 | } |
658 | 689 | ||
659 | private void LogIncomingToContentTypeHandler(OSHttpRequest request) | 690 | private void LogIncomingToContentTypeHandler(OSHttpRequest request) |
660 | { | 691 | { |
661 | m_log.DebugFormat( | 692 | m_log.DebugFormat( |
662 | "[BASE HTTP SERVER]: Found a {0} content type handler for {1} {2}", | 693 | "[BASE HTTP SERVER]: HTTP IN {0} :{1} {2} content type handler {3} {4} from {5}", |
663 | request.ContentType, request.HttpMethod, request.Url.PathAndQuery); | 694 | RequestNumber, |
664 | 695 | Port, | |
665 | if (DebugLevel >= 4) | 696 | request.ContentType, |
697 | request.HttpMethod, | ||
698 | request.Url.PathAndQuery, | ||
699 | request.RemoteIPEndPoint); | ||
700 | |||
701 | if (DebugLevel >= 5) | ||
666 | LogIncomingInDetail(request); | 702 | LogIncomingInDetail(request); |
667 | } | 703 | } |
668 | 704 | ||
669 | private void LogIncomingToXmlRpcHandler(OSHttpRequest request) | 705 | private void LogIncomingToXmlRpcHandler(OSHttpRequest request) |
670 | { | 706 | { |
671 | m_log.DebugFormat( | 707 | m_log.DebugFormat( |
672 | "[BASE HTTP SERVER]: Assuming a generic XMLRPC request for {0} {1}", | 708 | "[BASE HTTP SERVER]: HTTP IN {0} :{1} assumed generic XMLRPC request {2} {3} from {4}", |
673 | request.HttpMethod, request.Url.PathAndQuery); | 709 | RequestNumber, |
674 | 710 | Port, | |
675 | if (DebugLevel >= 4) | 711 | request.HttpMethod, |
712 | request.Url.PathAndQuery, | ||
713 | request.RemoteIPEndPoint); | ||
714 | |||
715 | if (DebugLevel >= 5) | ||
676 | LogIncomingInDetail(request); | 716 | LogIncomingInDetail(request); |
677 | } | 717 | } |
678 | 718 | ||
@@ -682,7 +722,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
682 | { | 722 | { |
683 | string output; | 723 | string output; |
684 | 724 | ||
685 | if (DebugLevel == 4) | 725 | if (DebugLevel == 5) |
686 | { | 726 | { |
687 | const int sampleLength = 80; | 727 | const int sampleLength = 80; |
688 | char[] sampleChars = new char[sampleLength]; | 728 | char[] sampleChars = new char[sampleLength]; |
@@ -790,24 +830,24 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
790 | } | 830 | } |
791 | } | 831 | } |
792 | 832 | ||
793 | private bool TryGetAgentHandler(OSHttpRequest request, OSHttpResponse response, out IHttpAgentHandler agentHandler) | 833 | // private bool TryGetAgentHandler(OSHttpRequest request, OSHttpResponse response, out IHttpAgentHandler agentHandler) |
794 | { | 834 | // { |
795 | agentHandler = null; | 835 | // agentHandler = null; |
796 | 836 | // | |
797 | lock (m_agentHandlers) | 837 | // lock (m_agentHandlers) |
798 | { | 838 | // { |
799 | foreach (IHttpAgentHandler handler in m_agentHandlers.Values) | 839 | // foreach (IHttpAgentHandler handler in m_agentHandlers.Values) |
800 | { | 840 | // { |
801 | if (handler.Match(request, response)) | 841 | // if (handler.Match(request, response)) |
802 | { | 842 | // { |
803 | agentHandler = handler; | 843 | // agentHandler = handler; |
804 | return true; | 844 | // return true; |
805 | } | 845 | // } |
806 | } | 846 | // } |
807 | } | 847 | // } |
808 | 848 | // | |
809 | return false; | 849 | // return false; |
810 | } | 850 | // } |
811 | 851 | ||
812 | /// <summary> | 852 | /// <summary> |
813 | /// Try all the registered xmlrpc handlers when an xmlrpc request is received. | 853 | /// Try all the registered xmlrpc handlers when an xmlrpc request is received. |
@@ -1778,21 +1818,21 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1778 | m_pollHandlers.Remove(path); | 1818 | m_pollHandlers.Remove(path); |
1779 | } | 1819 | } |
1780 | 1820 | ||
1781 | public bool RemoveAgentHandler(string agent, IHttpAgentHandler handler) | 1821 | // public bool RemoveAgentHandler(string agent, IHttpAgentHandler handler) |
1782 | { | 1822 | // { |
1783 | lock (m_agentHandlers) | 1823 | // lock (m_agentHandlers) |
1784 | { | 1824 | // { |
1785 | IHttpAgentHandler foundHandler; | 1825 | // IHttpAgentHandler foundHandler; |
1786 | 1826 | // | |
1787 | if (m_agentHandlers.TryGetValue(agent, out foundHandler) && foundHandler == handler) | 1827 | // if (m_agentHandlers.TryGetValue(agent, out foundHandler) && foundHandler == handler) |
1788 | { | 1828 | // { |
1789 | m_agentHandlers.Remove(agent); | 1829 | // m_agentHandlers.Remove(agent); |
1790 | return true; | 1830 | // return true; |
1791 | } | 1831 | // } |
1792 | } | 1832 | // } |
1793 | 1833 | // | |
1794 | return false; | 1834 | // return false; |
1795 | } | 1835 | // } |
1796 | 1836 | ||
1797 | public void RemoveXmlRPCHandler(string method) | 1837 | public void RemoveXmlRPCHandler(string method) |
1798 | { | 1838 | { |