some more cosmetics on http server

This commit is contained in:
UbitUmarov
2022-11-10 01:11:17 +00:00
parent 7ef28ede29
commit 70e50a4769
3 changed files with 212 additions and 339 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -73,14 +73,14 @@ namespace OpenSim.Framework.Servers.HttpServer
OSHttpResponse response = new OSHttpResponse(new HttpResponse(Request));
if (responsedata == null)
if (responsedata is null)
{
SendNoContentError(response);
return;
}
int responsecode = 200;
string responseString = String.Empty;
string responseString = null;
string contentType;
byte[] buffer = null;
int rangeStart = 0;
@@ -105,10 +105,7 @@ namespace OpenSim.Framework.Servers.HttpServer
}
else
responseString = (string)responsedata["str_response_string"];
contentType = (string)responsedata["content_type"];
if (responseString == null)
responseString = String.Empty;
}
catch
{
@@ -158,7 +155,9 @@ namespace OpenSim.Framework.Servers.HttpServer
if(buffer == null)
{
if (contentType != null && (!(contentType.Contains("image")
if(string.IsNullOrEmpty(responseString))
buffer = Array.Empty<byte>();
else if (contentType != null && (!(contentType.Contains("image")
|| contentType.Contains("x-shockwave-flash")
|| contentType.Contains("application/x-oar")
|| contentType.Contains("application/vnd.ll.mesh"))))

View File

@@ -400,9 +400,8 @@ namespace OpenSim.Server.Base
{
if (kvp.Value is List<string> l)
{
int llen = l.Count;
string nkey = System.Web.HttpUtility.UrlEncode(kvp.Key);
for (int i = 0; i < llen; ++i)
for (int i = 0; i < l.Count; ++i)
{
if (sb.Length != 0)
sb.Append('&');
@@ -414,19 +413,13 @@ namespace OpenSim.Server.Base
else if (kvp.Value is Dictionary<string, object>)
{
// encode complex structures as JSON
// needed for estate bans with the encoding used on xml
// encode can be here because object does contain the structure information
// but decode needs to be on estateSettings (or other user)
string js;
try
{
// bypass libovm, we dont need even more useless high level maps
// this should only be called once.. but no problem, i hope
// (other uses may need more..)
LitJson.JsonMapper.RegisterExporter<UUID>((uuid, writer) => writer.Write(uuid.ToString()));
js = LitJson.JsonMapper.ToJson(kvp.Value);
}
// catch(Exception e)
//catch(Exception e)
catch
{
continue;
@@ -534,21 +527,29 @@ namespace OpenSim.Server.Base
return ret;
}
private static readonly XmlReaderSettings ParseXmlStringResponseXmlReaderSettings = new()
{
IgnoreWhitespace = true,
IgnoreComments = true,
ConformanceLevel = ConformanceLevel.Fragment,
CloseInput = true,
MaxCharactersInDocument = 50_000_000
};
private static readonly XmlParserContext ParseXmlResponseXmlParserContext = new(null, null, null, XmlSpace.None)
{
Encoding = Util.UTF8NoBomEncoding
};
public static Dictionary<string, object> ParseXmlResponse(string data)
{
//m_log.DebugFormat("[XXX]: received xml string: {0}", data);
try
{
XmlReaderSettings xset = new XmlReaderSettings() { IgnoreWhitespace = true, IgnoreComments = true, ConformanceLevel = ConformanceLevel.Fragment, CloseInput = true };
XmlParserContext xpc = new XmlParserContext(null, null, null, XmlSpace.None);
xpc.Encoding = Util.UTF8NoBomEncoding;
using (XmlReader xr = XmlReader.Create(new StringReader(data), xset, xpc))
{
if (!xr.ReadToFollowing("ServerResponse"))
return new Dictionary<string, object>();
return ScanXmlResponse(xr);
}
using XmlReader xr = XmlReader.Create(new StringReader(data),
ParseXmlStringResponseXmlReaderSettings, ParseXmlResponseXmlParserContext);
if (!xr.ReadToFollowing("ServerResponse"))
return new Dictionary<string, object>();
return ScanXmlResponse(xr);
}
catch (Exception e)
{
@@ -557,26 +558,21 @@ namespace OpenSim.Server.Base
return new Dictionary<string, object>();
}
private static readonly XmlReaderSettings ParseXmlStreamResponseXmlReaderSettings = new()
{
IgnoreWhitespace = true,
IgnoreComments = true,
ConformanceLevel = ConformanceLevel.Fragment,
CloseInput = true,
MaxCharactersInDocument = 50_000_000
};
public static Dictionary<string, object> ParseXmlResponse(Stream src)
{
//m_log.DebugFormat("[XXX]: received xml string: {0}", data);
try
{
XmlReaderSettings xset = new XmlReaderSettings() { IgnoreWhitespace = true, IgnoreComments = true, ConformanceLevel = ConformanceLevel.Fragment, CloseInput = true };
XmlParserContext xpc = new XmlParserContext(null, null, null, XmlSpace.None);
xpc.Encoding = Util.UTF8NoBomEncoding;
using (XmlReader xr = XmlReader.Create(src, xset, xpc))
{
if (!xr.ReadToFollowing("ServerResponse"))
return new Dictionary<string, object>();
return ScanXmlResponse(xr);
}
}
catch (Exception e)
{
m_log.DebugFormat("[serverUtils.ParseXmlResponse]: failed error: {0}", e.Message);
}
using XmlReader xr = XmlReader.Create(src,
ParseXmlStreamResponseXmlReaderSettings, ParseXmlResponseXmlParserContext);
if (xr.ReadToFollowing("ServerResponse"))
return ScanXmlResponse(xr);
return new Dictionary<string, object>();
}