From 18402bc66796b991ccf65e86b0b36955d980ce8c Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 26 Dec 2020 03:34:07 +0000 Subject: [PATCH] simplify GridInfoHandlers a bit --- .../Server/Handlers/Grid/GridInfoHandlers.cs | 36 ++++++++++--------- .../Grid/GridInfoServerInConnector.cs | 4 +-- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs b/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs index 2aec04568b..7c503388fb 100644 --- a/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs +++ b/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs @@ -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("\n"); foreach (string k in _info.Keys) @@ -142,7 +147,7 @@ namespace OpenSim.Server.Handlers.Grid } sb.Append("\n"); - return sb.ToString(); + httpResponse.RawBuffer = Util.UTF8Getbytes(sb.ToString()); } /// @@ -152,14 +157,6 @@ namespace OpenSim.Server.Handlers.Grid /// /// json string /// - /// - /// Request. - /// - /// - /// /json_grid_info - /// - /// - /// Parameter. /// /// /// Http request. @@ -167,9 +164,14 @@ namespace OpenSim.Server.Handlers.Grid /// /// Http response. /// - 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(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); } } } diff --git a/OpenSim/Server/Handlers/Grid/GridInfoServerInConnector.cs b/OpenSim/Server/Handlers/Grid/GridInfoServerInConnector.cs index f6338f746f..5c157dbd27 100644 --- a/OpenSim/Server/Handlers/Grid/GridInfoServerInConnector.cs +++ b/OpenSim/Server/Handlers/Grid/GridInfoServerInConnector.cs @@ -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); }