From 23a8895d293f33e8dfcc4aaf56c6fcb49106e979 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Thu, 30 Jul 2009 18:16:00 +0000 Subject: * Fixed another potential httpserver leak. --- .../Framework/Servers/HttpServer/BaseHttpServer.cs | 7 ++++++- .../Framework/Servers/HttpServer/OSHttpResponse.cs | 19 +++++++++++++++++++ OpenSim/Framework/Servers/Tests/OSHttpTests.cs | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index d268457..fbd7166 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -1321,6 +1321,7 @@ namespace OpenSim.Framework.Servers.HttpServer string responseString = (string)responsedata["str_response_string"]; string contentType = (string)responsedata["content_type"]; + if (responsedata.ContainsKey("error_status_text")) { response.StatusDescription = (string)responsedata["error_status_text"]; @@ -1336,6 +1337,10 @@ namespace OpenSim.Framework.Servers.HttpServer response.KeepAlive = keepalive; } + + if (responsedata.ContainsKey("reusecontext")) + response.ReuseContext = (bool) responsedata["reusecontext"]; + //Even though only one other part of the entire code uses HTTPHandlers, we shouldn't expect this //and should check for NullReferenceExceptions @@ -1391,7 +1396,7 @@ namespace OpenSim.Framework.Servers.HttpServer response.OutputStream.Flush(); response.Send(); - if (!response.KeepAlive) + if (!response.KeepAlive && response.ReuseContext) response.FreeContext(); } catch (SocketException e) diff --git a/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs b/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs index 6c90a92..7029289 100644 --- a/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs +++ b/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs @@ -256,6 +256,25 @@ namespace OpenSim.Framework.Servers.HttpServer } } + public bool ReuseContext + { + get + { + if (_httpClientContext != null) + { + return !_httpClientContext.EndWhenDone; + } + return true; + } + set + { + if (_httpClientContext != null) + { + _httpClientContext.EndWhenDone = !value; + } + } + } + protected IHttpResponse _httpResponse; private IHttpClientContext _httpClientContext; diff --git a/OpenSim/Framework/Servers/Tests/OSHttpTests.cs b/OpenSim/Framework/Servers/Tests/OSHttpTests.cs index a6a90dc..e62407a 100644 --- a/OpenSim/Framework/Servers/Tests/OSHttpTests.cs +++ b/OpenSim/Framework/Servers/Tests/OSHttpTests.cs @@ -68,6 +68,7 @@ namespace OpenSim.Framework.Servers.Tests public void Send(byte[] buffer, int offset, int size) {} public void Respond(string httpVersion, HttpStatusCode statusCode, string reason, string body, string contentType) {} public void Close() { } + public bool EndWhenDone { get { return false;} set { return;}} public event EventHandler Disconnected = delegate { }; /// -- cgit v1.1