simplify GridInfoHandlers a bit

This commit is contained in:
UbitUmarov
2020-12-26 03:34:07 +00:00
parent 8316b9ff35
commit 18402bc667
2 changed files with 21 additions and 19 deletions

View File

@@ -130,10 +130,15 @@ namespace OpenSim.Server.Handlers.Grid
return response;
}
public string RestGetGridInfoMethod(string request, string path, string param,
IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
public void RestGetGridInfoMethod(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
{
StringBuilder sb = new StringBuilder();
if (httpRequest.HttpMethod != "GET")
{
httpResponse.StatusCode = (int)HttpStatusCode.MethodNotAllowed;
return;
}
StringBuilder sb = new StringBuilder(4096);
sb.Append("<gridinfo>\n");
foreach (string k in _info.Keys)
@@ -142,7 +147,7 @@ namespace OpenSim.Server.Handlers.Grid
}
sb.Append("</gridinfo>\n");
return sb.ToString();
httpResponse.RawBuffer = Util.UTF8Getbytes(sb.ToString());
}
/// <summary>
@@ -152,14 +157,6 @@ namespace OpenSim.Server.Handlers.Grid
/// <returns>
/// json string
/// </returns>
/// <param name='request'>
/// Request.
/// </param>
/// <param name='path'>
/// /json_grid_info
/// </param>
/// <param name='param'>
/// Parameter.
/// </param>
/// <param name='httpRequest'>
/// Http request.
@@ -167,9 +164,14 @@ namespace OpenSim.Server.Handlers.Grid
/// <param name='httpResponse'>
/// Http response.
/// </param>
public string JsonGetGridInfoMethod(string request, string path, string param,
IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
public void JsonGetGridInfoMethod(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
{
if (httpRequest.HttpMethod != "GET")
{
httpResponse.StatusCode = (int)HttpStatusCode.MethodNotAllowed;
return;
}
OSDMap map = new OSDMap();
foreach (string k in _info.Keys)
@@ -180,7 +182,7 @@ namespace OpenSim.Server.Handlers.Grid
string HomeURI = Util.GetConfigVarFromSections<string>(m_Config, "HomeURI",
new string[] { "Startup", "Hypergrid" }, String.Empty);
if (!String.IsNullOrEmpty(HomeURI))
if (!string.IsNullOrEmpty(HomeURI))
map["home"] = OSD.FromString(HomeURI);
else // Legacy. Remove soon!
{
@@ -189,11 +191,11 @@ namespace OpenSim.Server.Handlers.Grid
if (null != cfg)
HomeURI = cfg.GetString("SRV_HomeURI", HomeURI);
if (!String.IsNullOrEmpty(HomeURI))
if (!string.IsNullOrEmpty(HomeURI))
map["home"] = OSD.FromString(HomeURI);
}
return OSDParser.SerializeJsonString(map).ToString();
httpResponse.RawBuffer = OSDParser.SerializeJsonToBytes(map);
}
}
}

View File

@@ -46,9 +46,9 @@ namespace OpenSim.Server.Handlers.Grid
{
GridInfoHandlers handlers = new GridInfoHandlers(config);
server.AddStreamHandler(new RestStreamHandler("GET", "/get_grid_info",
server.AddSimpleStreamHandler(new SimpleStreamHandler("/get_grid_info",
handlers.RestGetGridInfoMethod));
server.AddStreamHandler(new RestStreamHandler("GET", "/json_grid_info",
server.AddSimpleStreamHandler(new SimpleStreamHandler("/json_grid_info",
handlers.JsonGetGridInfoMethod));
server.AddXmlRPCHandler("get_grid_info", handlers.XmlRpcGridInfoMethod);
}