clean a bit

0.9.1.0-post-fixes
UbitUmarov 2018-12-03 13:51:45 +00:00
parent 66f3c6c730
commit 037de89a75
3 changed files with 57 additions and 70 deletions

View File

@ -604,7 +604,7 @@ namespace OpenSim.Framework.Servers.HttpServer
return; return;
} }
OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context); OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request));
HandleRequest(req, resp); HandleRequest(req, resp);
@ -676,8 +676,6 @@ namespace OpenSim.Framework.Servers.HttpServer
// } // }
// } // }
response.SendChunked = false;
string path = request.RawUrl; string path = request.RawUrl;
string handlerKey = GetHandlerKey(request.HttpMethod, path); string handlerKey = GetHandlerKey(request.HttpMethod, path);
byte[] buffer = null; byte[] buffer = null;
@ -1308,7 +1306,6 @@ namespace OpenSim.Framework.Servers.HttpServer
byte[] buffer = Encoding.UTF8.GetBytes(responseString); byte[] buffer = Encoding.UTF8.GetBytes(responseString);
response.SendChunked = false;
response.ContentLength64 = buffer.Length; response.ContentLength64 = buffer.Length;
response.ContentEncoding = Encoding.UTF8; response.ContentEncoding = Encoding.UTF8;
@ -1480,7 +1477,6 @@ namespace OpenSim.Framework.Servers.HttpServer
buffer = BuildLLSDResponse(request, response, llsdResponse); buffer = BuildLLSDResponse(request, response, llsdResponse);
} }
response.SendChunked = false;
response.ContentLength64 = buffer.Length; response.ContentLength64 = buffer.Length;
response.ContentEncoding = Encoding.UTF8; response.ContentEncoding = Encoding.UTF8;
response.KeepAlive = true; response.KeepAlive = true;
@ -1988,7 +1984,6 @@ namespace OpenSim.Framework.Servers.HttpServer
buffer = Convert.FromBase64String(responseString); buffer = Convert.FromBase64String(responseString);
} }
response.SendChunked = false;
response.ContentLength64 = buffer.Length; response.ContentLength64 = buffer.Length;
response.ContentEncoding = Encoding.UTF8; response.ContentEncoding = Encoding.UTF8;
} }
@ -2005,7 +2000,6 @@ namespace OpenSim.Framework.Servers.HttpServer
string responseString = GetHTTP404(host); string responseString = GetHTTP404(host);
byte[] buffer = Encoding.UTF8.GetBytes(responseString); byte[] buffer = Encoding.UTF8.GetBytes(responseString);
response.SendChunked = false;
response.ContentLength64 = buffer.Length; response.ContentLength64 = buffer.Length;
response.ContentEncoding = Encoding.UTF8; response.ContentEncoding = Encoding.UTF8;
@ -2021,11 +2015,9 @@ namespace OpenSim.Framework.Servers.HttpServer
string responseString = GetHTTP500(); string responseString = GetHTTP500();
byte[] buffer = Encoding.UTF8.GetBytes(responseString); byte[] buffer = Encoding.UTF8.GetBytes(responseString);
response.SendChunked = false;
response.ContentLength64 = buffer.Length; response.ContentLength64 = buffer.Length;
response.ContentEncoding = Encoding.UTF8; response.ContentEncoding = Encoding.UTF8;
return buffer; return buffer;
} }

View File

@ -251,12 +251,12 @@ namespace OpenSim.Framework.Servers.HttpServer
{ {
get get
{ {
return _httpResponse.Chunked; return _httpResponse.Chunked;
} }
set set
{ {
_httpResponse.Chunked = value; _httpResponse.Chunked = value;
} }
} }
@ -294,7 +294,6 @@ namespace OpenSim.Framework.Servers.HttpServer
} }
protected IHttpResponse _httpResponse; protected IHttpResponse _httpResponse;
private IHttpClientContext _httpClientContext;
public OSHttpResponse() {} public OSHttpResponse() {}
@ -312,12 +311,12 @@ namespace OpenSim.Framework.Servers.HttpServer
public OSHttpResponse(OSHttpRequest req) public OSHttpResponse(OSHttpRequest req)
{ {
_httpResponse = new HttpResponse(req.IHttpClientContext, req.IHttpRequest); _httpResponse = new HttpResponse(req.IHttpClientContext, req.IHttpRequest);
_httpClientContext = req.IHttpClientContext;
} }
public OSHttpResponse(HttpResponse resp, IHttpClientContext clientContext)
public OSHttpResponse(HttpResponse resp)
{ {
_httpResponse = resp; _httpResponse = resp;
_httpClientContext = clientContext;
} }
/// <summary> /// <summary>
@ -337,13 +336,8 @@ namespace OpenSim.Framework.Servers.HttpServer
/// </summary> /// </summary>
public void Send() public void Send()
{ {
_httpResponse.Chunked = false;
_httpResponse.Send(); _httpResponse.Send();
} }
public void FreeContext()
{
if (_httpClientContext != null)
_httpClientContext.Close();
}
} }
} }

View File

@ -85,7 +85,13 @@ namespace OpenSim.Framework.Servers.HttpServer
Request.Body.Dispose(); Request.Body.Dispose();
OSHttpResponse response OSHttpResponse response
= new OSHttpResponse(new HttpResponse(HttpContext, Request), HttpContext); = new OSHttpResponse(new HttpResponse(HttpContext, Request));
if (responsedata == null)
{
SendNoContentError(response);
return;
}
int responsecode = 200; int responsecode = 200;
string responseString = String.Empty; string responseString = String.Empty;
@ -94,61 +100,44 @@ namespace OpenSim.Framework.Servers.HttpServer
int rangeStart = 0; int rangeStart = 0;
int rangeLen = -1; int rangeLen = -1;
if (responsedata == null) try
{ {
responsecode = 500; //m_log.Info("[BASE HTTP SERVER]: Doing HTTP Grunt work with response");
responseString = "No response could be obtained"; if(responsedata["int_response_code"] != null)
contentType = "text/plain"; responsecode = (int)responsedata["int_response_code"];
responsedata = new Hashtable();
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 SendNoContentError(response);
{ return;
//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();
}
} }
if (responsedata.ContainsKey("error_status_text")) if (responsedata.ContainsKey("error_status_text"))
{
response.StatusDescription = (string)responsedata["error_status_text"]; response.StatusDescription = (string)responsedata["error_status_text"];
}
if (responsedata.ContainsKey("http_protocol_version")) if (responsedata.ContainsKey("http_protocol_version"))
{
response.ProtocolVersion = (string)responsedata["http_protocol_version"]; response.ProtocolVersion = (string)responsedata["http_protocol_version"];
}
if (responsedata.ContainsKey("keepalive")) if (responsedata.ContainsKey("keepalive"))
{ response.KeepAlive = (bool)responsedata["keepalive"];
bool keepalive = (bool)responsedata["keepalive"];
response.KeepAlive = keepalive;
}
// Cross-Origin Resource Sharing with simple requests // Cross-Origin Resource Sharing with simple requests
if (responsedata.ContainsKey("access_control_allow_origin")) if (responsedata.ContainsKey("access_control_allow_origin"))
@ -200,7 +189,6 @@ namespace OpenSim.Framework.Servers.HttpServer
else if (rangeLen + rangeStart > buffer.Length) else if (rangeLen + rangeStart > buffer.Length)
rangeLen = buffer.Length - rangeStart; rangeLen = buffer.Length - rangeStart;
response.SendChunked = false;
response.ContentLength64 = rangeLen; response.ContentLength64 = rangeLen;
try try
@ -233,10 +221,24 @@ namespace OpenSim.Framework.Servers.HttpServer
PollServiceArgs.RequestsHandled++; 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() internal void DoHTTPstop()
{ {
OSHttpResponse response OSHttpResponse response
= new OSHttpResponse(new HttpResponse(HttpContext, Request), HttpContext); = new OSHttpResponse(new HttpResponse(HttpContext, Request));
if(Request.Body.CanRead) if(Request.Body.CanRead)
Request.Body.Dispose(); Request.Body.Dispose();
@ -244,7 +246,6 @@ namespace OpenSim.Framework.Servers.HttpServer
response.ContentLength64 = 0; response.ContentLength64 = 0;
response.ContentEncoding = Encoding.UTF8; response.ContentEncoding = Encoding.UTF8;
response.KeepAlive = false; response.KeepAlive = false;
response.SendChunked = false;
response.StatusCode = 503; response.StatusCode = 503;
try try