diff options
Diffstat (limited to 'OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs')
-rw-r--r-- | OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 59 |
1 files changed, 48 insertions, 11 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 97035e3..7841f47 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | |||
@@ -54,7 +54,6 @@ 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 | |||
58 | /// <summary> | 57 | /// <summary> |
59 | /// This is a pending websocket request before it got an sucessful upgrade response. | 58 | /// This is a pending websocket request before it got an sucessful upgrade response. |
60 | /// The consumer must call handler.HandshakeAndUpgrade() to signal to the handler to | 59 | /// The consumer must call handler.HandshakeAndUpgrade() to signal to the handler to |
@@ -81,6 +80,11 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
81 | /// </remarks> | 80 | /// </remarks> |
82 | public int RequestNumber { get; private set; } | 81 | public int RequestNumber { get; private set; } |
83 | 82 | ||
83 | /// <summary> | ||
84 | /// Statistic for holding number of requests processed. | ||
85 | /// </summary> | ||
86 | private Stat m_requestsProcessedStat; | ||
87 | |||
84 | private volatile int NotSocketErrors = 0; | 88 | private volatile int NotSocketErrors = 0; |
85 | public volatile bool HTTPDRunning = false; | 89 | public volatile bool HTTPDRunning = false; |
86 | 90 | ||
@@ -383,6 +387,8 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
383 | 387 | ||
384 | if (TryGetPollServiceHTTPHandler(request.UriPath.ToString(), out psEvArgs)) | 388 | if (TryGetPollServiceHTTPHandler(request.UriPath.ToString(), out psEvArgs)) |
385 | { | 389 | { |
390 | psEvArgs.RequestsReceived++; | ||
391 | |||
386 | PollServiceHttpRequest psreq = new PollServiceHttpRequest(psEvArgs, context, request); | 392 | PollServiceHttpRequest psreq = new PollServiceHttpRequest(psEvArgs, context, request); |
387 | 393 | ||
388 | if (psEvArgs.Request != null) | 394 | if (psEvArgs.Request != null) |
@@ -437,9 +443,8 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
437 | } | 443 | } |
438 | } | 444 | } |
439 | 445 | ||
440 | public void OnHandleRequestIOThread(IHttpClientContext context, IHttpRequest request) | 446 | private void OnHandleRequestIOThread(IHttpClientContext context, IHttpRequest request) |
441 | { | 447 | { |
442 | |||
443 | OSHttpRequest req = new OSHttpRequest(context, request); | 448 | OSHttpRequest req = new OSHttpRequest(context, request); |
444 | WebSocketRequestDelegate dWebSocketRequestDelegate = null; | 449 | WebSocketRequestDelegate dWebSocketRequestDelegate = null; |
445 | lock (m_WebSocketHandlers) | 450 | lock (m_WebSocketHandlers) |
@@ -454,9 +459,8 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
454 | } | 459 | } |
455 | 460 | ||
456 | OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context); | 461 | OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context); |
457 | 462 | resp.ReuseContext = true; | |
458 | HandleRequest(req, resp); | 463 | HandleRequest(req, resp); |
459 | |||
460 | 464 | ||
461 | // !!!HACK ALERT!!! | 465 | // !!!HACK ALERT!!! |
462 | // There seems to be a bug in the underlying http code that makes subsequent requests | 466 | // There seems to be a bug in the underlying http code that makes subsequent requests |
@@ -687,7 +691,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
687 | 691 | ||
688 | if (buffer != null) | 692 | if (buffer != null) |
689 | { | 693 | { |
690 | if (!response.SendChunked) | 694 | if (!response.SendChunked && response.ContentLength64 <= 0) |
691 | response.ContentLength64 = buffer.LongLength; | 695 | response.ContentLength64 = buffer.LongLength; |
692 | 696 | ||
693 | response.OutputStream.Write(buffer, 0, buffer.Length); | 697 | response.OutputStream.Write(buffer, 0, buffer.Length); |
@@ -782,7 +786,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
782 | "[BASE HTTP SERVER]: HTTP IN {0} :{1} {2} content type handler {3} {4} from {5}", | 786 | "[BASE HTTP SERVER]: HTTP IN {0} :{1} {2} content type handler {3} {4} from {5}", |
783 | RequestNumber, | 787 | RequestNumber, |
784 | Port, | 788 | Port, |
785 | (request.ContentType == null || request.ContentType == "") ? "not set" : request.ContentType, | 789 | string.IsNullOrEmpty(request.ContentType) ? "not set" : request.ContentType, |
786 | request.HttpMethod, | 790 | request.HttpMethod, |
787 | request.Url.PathAndQuery, | 791 | request.Url.PathAndQuery, |
788 | request.RemoteIPEndPoint); | 792 | request.RemoteIPEndPoint); |
@@ -1053,7 +1057,21 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1053 | } | 1057 | } |
1054 | 1058 | ||
1055 | response.ContentType = "text/xml"; | 1059 | response.ContentType = "text/xml"; |
1056 | responseString = XmlRpcResponseSerializer.Singleton.Serialize(xmlRpcResponse); | 1060 | using (MemoryStream outs = new MemoryStream()) |
1061 | { | ||
1062 | using (XmlTextWriter writer = new XmlTextWriter(outs, Encoding.UTF8)) | ||
1063 | { | ||
1064 | writer.Formatting = Formatting.None; | ||
1065 | XmlRpcResponseSerializer.Singleton.Serialize(writer, xmlRpcResponse); | ||
1066 | writer.Flush(); | ||
1067 | outs.Flush(); | ||
1068 | outs.Position = 0; | ||
1069 | using (StreamReader sr = new StreamReader(outs)) | ||
1070 | { | ||
1071 | responseString = sr.ReadToEnd(); | ||
1072 | } | ||
1073 | } | ||
1074 | } | ||
1057 | } | 1075 | } |
1058 | else | 1076 | else |
1059 | { | 1077 | { |
@@ -1850,8 +1868,8 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1850 | m_httpListener2.Start(64); | 1868 | m_httpListener2.Start(64); |
1851 | 1869 | ||
1852 | // Long Poll Service Manager with 3 worker threads a 25 second timeout for no events | 1870 | // Long Poll Service Manager with 3 worker threads a 25 second timeout for no events |
1853 | // m_PollServiceManager = new PollServiceRequestManager(this, 3, 25000); | ||
1854 | m_PollServiceManager = new PollServiceRequestManager(this, 4, 25000); | 1871 | m_PollServiceManager = new PollServiceRequestManager(this, 4, 25000); |
1872 | m_PollServiceManager.Start(); | ||
1855 | HTTPDRunning = true; | 1873 | HTTPDRunning = true; |
1856 | 1874 | ||
1857 | //HttpListenerContext context; | 1875 | //HttpListenerContext context; |
@@ -1870,6 +1888,21 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1870 | // useful without inbound HTTP. | 1888 | // useful without inbound HTTP. |
1871 | throw e; | 1889 | throw e; |
1872 | } | 1890 | } |
1891 | |||
1892 | m_requestsProcessedStat | ||
1893 | = new Stat( | ||
1894 | "HTTPRequestsServed", | ||
1895 | "Number of inbound HTTP requests processed", | ||
1896 | "", | ||
1897 | "requests", | ||
1898 | "httpserver", | ||
1899 | Port.ToString(), | ||
1900 | StatType.Pull, | ||
1901 | MeasuresOfInterest.AverageChangeOverTime, | ||
1902 | stat => stat.Value = RequestNumber, | ||
1903 | StatVerbosity.Debug); | ||
1904 | |||
1905 | StatsManager.RegisterStat(m_requestsProcessedStat); | ||
1873 | } | 1906 | } |
1874 | 1907 | ||
1875 | public void httpServerDisconnectMonitor(IHttpClientContext source, SocketError err) | 1908 | public void httpServerDisconnectMonitor(IHttpClientContext source, SocketError err) |
@@ -1902,9 +1935,12 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1902 | public void Stop() | 1935 | public void Stop() |
1903 | { | 1936 | { |
1904 | HTTPDRunning = false; | 1937 | HTTPDRunning = false; |
1938 | |||
1939 | StatsManager.DeregisterStat(m_requestsProcessedStat); | ||
1940 | |||
1905 | try | 1941 | try |
1906 | { | 1942 | { |
1907 | // m_PollServiceManager.Stop(); | 1943 | m_PollServiceManager.Stop(); |
1908 | 1944 | ||
1909 | m_httpListener2.ExceptionThrown -= httpServerException; | 1945 | m_httpListener2.ExceptionThrown -= httpServerException; |
1910 | //m_httpListener2.DisconnectHandler = null; | 1946 | //m_httpListener2.DisconnectHandler = null; |
@@ -1931,6 +1967,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1931 | 1967 | ||
1932 | public void RemoveHTTPHandler(string httpMethod, string path) | 1968 | public void RemoveHTTPHandler(string httpMethod, string path) |
1933 | { | 1969 | { |
1970 | if (path == null) return; // Caps module isn't loaded, tries to remove handler where path = null | ||
1934 | lock (m_HTTPHandlers) | 1971 | lock (m_HTTPHandlers) |
1935 | { | 1972 | { |
1936 | if (httpMethod != null && httpMethod.Length == 0) | 1973 | if (httpMethod != null && httpMethod.Length == 0) |