diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index fe3b8a02a7..5bb3fe2bdc 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -604,7 +604,7 @@ namespace OpenSim.Framework.Servers.HttpServer return; } - OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context); + OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request)); HandleRequest(req, resp); @@ -676,8 +676,6 @@ namespace OpenSim.Framework.Servers.HttpServer // } // } - response.SendChunked = false; - string path = request.RawUrl; string handlerKey = GetHandlerKey(request.HttpMethod, path); byte[] buffer = null; @@ -1308,7 +1306,6 @@ namespace OpenSim.Framework.Servers.HttpServer byte[] buffer = Encoding.UTF8.GetBytes(responseString); - response.SendChunked = false; response.ContentLength64 = buffer.Length; response.ContentEncoding = Encoding.UTF8; @@ -1480,7 +1477,6 @@ namespace OpenSim.Framework.Servers.HttpServer buffer = BuildLLSDResponse(request, response, llsdResponse); } - response.SendChunked = false; response.ContentLength64 = buffer.Length; response.ContentEncoding = Encoding.UTF8; response.KeepAlive = true; @@ -1988,7 +1984,6 @@ namespace OpenSim.Framework.Servers.HttpServer buffer = Convert.FromBase64String(responseString); } - response.SendChunked = false; response.ContentLength64 = buffer.Length; response.ContentEncoding = Encoding.UTF8; } @@ -2005,7 +2000,6 @@ namespace OpenSim.Framework.Servers.HttpServer string responseString = GetHTTP404(host); byte[] buffer = Encoding.UTF8.GetBytes(responseString); - response.SendChunked = false; response.ContentLength64 = buffer.Length; response.ContentEncoding = Encoding.UTF8; @@ -2021,11 +2015,9 @@ namespace OpenSim.Framework.Servers.HttpServer string responseString = GetHTTP500(); byte[] buffer = Encoding.UTF8.GetBytes(responseString); - response.SendChunked = false; response.ContentLength64 = buffer.Length; response.ContentEncoding = Encoding.UTF8; - return buffer; } diff --git a/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs b/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs index 39d9b13ab3..5a49881902 100644 --- a/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs +++ b/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs @@ -251,12 +251,12 @@ namespace OpenSim.Framework.Servers.HttpServer { get { - return _httpResponse.Chunked; + return _httpResponse.Chunked; } set { - _httpResponse.Chunked = value; + _httpResponse.Chunked = value; } } @@ -294,7 +294,6 @@ namespace OpenSim.Framework.Servers.HttpServer } protected IHttpResponse _httpResponse; - private IHttpClientContext _httpClientContext; public OSHttpResponse() {} @@ -312,12 +311,12 @@ namespace OpenSim.Framework.Servers.HttpServer public OSHttpResponse(OSHttpRequest req) { _httpResponse = new HttpResponse(req.IHttpClientContext, req.IHttpRequest); - _httpClientContext = req.IHttpClientContext; + } - public OSHttpResponse(HttpResponse resp, IHttpClientContext clientContext) + + public OSHttpResponse(HttpResponse resp) { _httpResponse = resp; - _httpClientContext = clientContext; } /// @@ -337,13 +336,8 @@ namespace OpenSim.Framework.Servers.HttpServer /// public void Send() { + _httpResponse.Chunked = false; _httpResponse.Send(); } - - public void FreeContext() - { - if (_httpClientContext != null) - _httpClientContext.Close(); - } } } \ No newline at end of file diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs index 47a0b9c0dc..f83b771b16 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs @@ -85,7 +85,13 @@ namespace OpenSim.Framework.Servers.HttpServer Request.Body.Dispose(); OSHttpResponse response - = new OSHttpResponse(new HttpResponse(HttpContext, Request), HttpContext); + = new OSHttpResponse(new HttpResponse(HttpContext, Request)); + + if (responsedata == null) + { + SendNoContentError(response); + return; + } int responsecode = 200; string responseString = String.Empty; @@ -94,61 +100,44 @@ namespace OpenSim.Framework.Servers.HttpServer int rangeStart = 0; int rangeLen = -1; - if (responsedata == null) + try { - responsecode = 500; - responseString = "No response could be obtained"; - contentType = "text/plain"; - responsedata = new Hashtable(); + //m_log.Info("[BASE HTTP SERVER]: Doing HTTP Grunt work with response"); + if(responsedata["int_response_code"] != null) + responsecode = (int)responsedata["int_response_code"]; + + if (responsedata["bin_response_data"] != null) + { + buffer = (byte[])responsedata["bin_response_data"]; + responsedata["bin_response_data"] = null; + + if (responsedata["bin_start"] != null) + rangeStart = (int)responsedata["bin_start"]; + + if (responsedata["int_bytes"] != null) + rangeLen = (int)responsedata["int_bytes"]; + } + else + responseString = (string)responsedata["str_response_string"]; + + contentType = (string)responsedata["content_type"]; + if (responseString == null) + responseString = String.Empty; } - else + catch { - try - { - //m_log.Info("[BASE HTTP SERVER]: Doing HTTP Grunt work with response"); - if(responsedata["int_response_code"] != null) - responsecode = (int)responsedata["int_response_code"]; - - if (responsedata["bin_response_data"] != null) - { - buffer = (byte[])responsedata["bin_response_data"]; - responsedata["bin_response_data"] = null; - - if (responsedata["bin_start"] != null) - rangeStart = (int)responsedata["bin_start"]; - - if (responsedata["int_bytes"] != null) - rangeLen = (int)responsedata["int_bytes"]; - } - else - responseString = (string)responsedata["str_response_string"]; - - contentType = (string)responsedata["content_type"]; - if (responseString == null) - responseString = String.Empty; - } - catch - { - responsecode = 500; - responseString = "No response could be obtained"; - contentType = "text/plain"; - responsedata = new Hashtable(); - } + SendNoContentError(response); + return; } if (responsedata.ContainsKey("error_status_text")) - { response.StatusDescription = (string)responsedata["error_status_text"]; - } + if (responsedata.ContainsKey("http_protocol_version")) - { response.ProtocolVersion = (string)responsedata["http_protocol_version"]; - } + if (responsedata.ContainsKey("keepalive")) - { - bool keepalive = (bool)responsedata["keepalive"]; - response.KeepAlive = keepalive; - } + response.KeepAlive = (bool)responsedata["keepalive"]; // Cross-Origin Resource Sharing with simple requests if (responsedata.ContainsKey("access_control_allow_origin")) @@ -200,7 +189,6 @@ namespace OpenSim.Framework.Servers.HttpServer else if (rangeLen + rangeStart > buffer.Length) rangeLen = buffer.Length - rangeStart; - response.SendChunked = false; response.ContentLength64 = rangeLen; try @@ -233,10 +221,24 @@ namespace OpenSim.Framework.Servers.HttpServer PollServiceArgs.RequestsHandled++; } + internal void SendNoContentError(OSHttpResponse response) + { + response.ContentLength64 = 0; + response.ContentEncoding = Encoding.UTF8; + response.StatusCode = 500; + + try + { + response.Send(); + } + catch { } + return; + } + internal void DoHTTPstop() { OSHttpResponse response - = new OSHttpResponse(new HttpResponse(HttpContext, Request), HttpContext); + = new OSHttpResponse(new HttpResponse(HttpContext, Request)); if(Request.Body.CanRead) Request.Body.Dispose(); @@ -244,7 +246,6 @@ namespace OpenSim.Framework.Servers.HttpServer response.ContentLength64 = 0; response.ContentEncoding = Encoding.UTF8; response.KeepAlive = false; - response.SendChunked = false; response.StatusCode = 503; try