From a845c1a893a203f1a9bc38dc754a6f94e4c02ea5 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Wed, 7 May 2014 19:38:33 -0700 Subject: [PATCH] Finished implementing redirects in GetTexture. --- .../Handlers/GetTexture/GetTextureHandler.cs | 12 ++++++++---- .../Handlers/GetTexture/GetTextureServerConnector.cs | 4 +++- .../GetTexture/Tests/GetTextureHandlerTests.cs | 2 +- .../ClientStack/Linden/Caps/GetTextureModule.cs | 9 ++++++--- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs index 7b3124af57..4dfa847463 100644 --- a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs +++ b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs @@ -56,12 +56,15 @@ namespace OpenSim.Capabilities.Handlers public const string DefaultFormat = "x-j2c"; // TODO: Change this to a config option - const string REDIRECT_URL = null; + private string m_RedirectURL = null; - public GetTextureHandler(string path, IAssetService assService, string name, string description) + public GetTextureHandler(string path, IAssetService assService, string name, string description, string redirectURL) : base("GET", path, name, description) { m_assetService = assService; + m_RedirectURL = redirectURL; + if (!m_RedirectURL.EndsWith("/")) + m_RedirectURL += "/"; } protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) @@ -134,7 +137,7 @@ namespace OpenSim.Capabilities.Handlers if (format != DefaultFormat) fullID = fullID + "-" + format; - if (!String.IsNullOrEmpty(REDIRECT_URL)) + if (!String.IsNullOrEmpty(m_RedirectURL)) { // Only try to fetch locally cached textures. Misses are redirected texture = m_assetService.GetCached(fullID); @@ -150,8 +153,9 @@ namespace OpenSim.Capabilities.Handlers } else { - string textureUrl = REDIRECT_URL + textureID.ToString(); + string textureUrl = m_RedirectURL + textureID.ToString(); m_log.Debug("[GETTEXTURE]: Redirecting texture request to " + textureUrl); + httpResponse.StatusCode = (int)OSHttpStatusCode.RedirectMovedPermanently; httpResponse.RedirectLocation = textureUrl; return true; } diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs index 71cf033437..fa0b2280ef 100644 --- a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs +++ b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs @@ -62,8 +62,10 @@ namespace OpenSim.Capabilities.Handlers if (m_AssetService == null) throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); + string rurl = serverConfig.GetString("GetTextureRedirectURL"); + ; server.AddStreamHandler( - new GetTextureHandler("/CAPS/GetTexture/" /*+ UUID.Random() */, m_AssetService, "GetTexture", null)); + new GetTextureHandler("/CAPS/GetTexture/" /*+ UUID.Random() */, m_AssetService, "GetTexture", null, rurl)); } } } \ No newline at end of file diff --git a/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs b/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs index d4d6d10d83..8ffafa4889 100644 --- a/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs +++ b/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs @@ -52,7 +52,7 @@ namespace OpenSim.Capabilities.Handlers.GetTexture.Tests // Overkill - we only really need the asset service, not a whole scene. Scene scene = new SceneHelpers().SetupScene(); - GetTextureHandler handler = new GetTextureHandler(null, scene.AssetService, "TestGetTexture", null); + GetTextureHandler handler = new GetTextureHandler(null, scene.AssetService, "TestGetTexture", null, null); TestOSHttpRequest req = new TestOSHttpRequest(); TestOSHttpResponse resp = new TestOSHttpResponse(); req.Url = new Uri("http://localhost/?texture_id=00000000-0000-1111-9999-000000000012"); diff --git a/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs index 54cf285cf6..bb932f293f 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs @@ -63,7 +63,7 @@ namespace OpenSim.Region.ClientStack.Linden private bool m_Enabled = false; // TODO: Change this to a config option - const string REDIRECT_URL = null; + private string m_RedirectURL = null; private string m_URL; @@ -78,7 +78,10 @@ namespace OpenSim.Region.ClientStack.Linden m_URL = config.GetString("Cap_GetTexture", string.Empty); // Cap doesn't exist if (m_URL != string.Empty) + { m_Enabled = true; + m_RedirectURL = config.GetString("GetTextureRedirectURL"); + } } public void AddRegion(Scene s) @@ -132,14 +135,14 @@ namespace OpenSim.Region.ClientStack.Linden // m_log.DebugFormat("[GETTEXTURE]: /CAPS/{0} in region {1}", capID, m_scene.RegionInfo.RegionName); caps.RegisterHandler( "GetTexture", - new GetTextureHandler("/CAPS/" + capID + "/", m_assetService, "GetTexture", agentID.ToString())); + new GetTextureHandler("/CAPS/" + capID + "/", m_assetService, "GetTexture", agentID.ToString(), m_RedirectURL)); } else { // m_log.DebugFormat("[GETTEXTURE]: {0} in region {1}", m_URL, m_scene.RegionInfo.RegionName); IExternalCapsModule handler = m_scene.RequestModuleInterface(); if (handler != null) - handler.RegisterExternalUserCapsHandler(agentID,caps,"GetTexture",m_URL); + handler.RegisterExternalUserCapsHandler(agentID,caps,"GetTexture", m_URL); else caps.RegisterHandler("GetTexture", m_URL); }