From c40b297fc7a91c5f012b64096de05e44cee9c2b0 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 11 May 2020 23:07:29 +0100 Subject: [PATCH] (TEST) add a default root uri GET handler. this may be usefull for some cases. --- .../Servers/HttpServer/BaseHttpServer.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 1a676dd98a..efb7c169c9 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -108,6 +108,8 @@ namespace OpenSim.Framework.Servers.HttpServer protected ConcurrentDictionary m_simpleStreamVarPath = new ConcurrentDictionary(); protected ConcurrentDictionary m_indexPHPmethods = new ConcurrentDictionary(); + protected IRequestHandler m_RootDefaultGET = null; // default method for root path. does override rpc xml and json, and old llsd login + protected uint m_port; protected bool m_ssl; private X509Certificate2 m_cert; @@ -328,6 +330,15 @@ namespace OpenSim.Framework.Servers.HttpServer { string httpMethod = handler.HttpMethod; string path = handler.Path; + + if(path == "/") + { + if(httpMethod == "GET" && (handler is IStreamedRequestHandler || handler is ISimpleStreamHandler)) + m_RootDefaultGET = handler; + + return; + } + string handlerKey = GetHandlerKey(httpMethod, path); // m_log.DebugFormat("[BASE HTTP SERVER]: Adding handler key {0}", handlerKey); @@ -620,6 +631,28 @@ namespace OpenSim.Framework.Servers.HttpServer if (path == "/") { response.StatusCode = (int)HttpStatusCode.NotFound; // default + + if (m_RootDefaultGET != null && request.HttpMethod == "GET") + { + if(m_RootDefaultGET is IStreamedRequestHandler) + { + IStreamedRequestHandler isrh = m_RootDefaultGET as IStreamedRequestHandler; + response.RawBuffer = isrh.Handle(path, request.InputStream, request, response); + response.StatusCode = (int)HttpStatusCode.OK; + } + else if (m_RootDefaultGET is ISimpleStreamHandler) + { + ISimpleStreamHandler issh = m_RootDefaultGET as ISimpleStreamHandler; + issh.Handle(request, response); + } + if (request.InputStream != null && request.InputStream.CanRead) + request.InputStream.Dispose(); + + requestEndTick = Environment.TickCount; + response.Send(); + return; + } + switch (request.ContentType) { case "application/json-rpc":