From 449548d7a4e3571597b5e4bec53e3f42ebdf6015 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 26 May 2014 08:13:49 -0700 Subject: Adds an optional redirect URL to the asset server handler for when assets are not found locally. --- .../Server/Handlers/Asset/AssetServerGetHandler.cs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs index 500ec50..91c5c54 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs @@ -48,6 +48,7 @@ namespace OpenSim.Server.Handlers.Asset private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private IAssetService m_AssetService; + private string m_RedirectURL; public AssetServerGetHandler(IAssetService service) : base("GET", "/assets") @@ -55,10 +56,13 @@ namespace OpenSim.Server.Handlers.Asset m_AssetService = service; } - public AssetServerGetHandler(IAssetService service, IServiceAuth auth) : + public AssetServerGetHandler(IAssetService service, IServiceAuth auth, string redirectURL) : base("GET", "/assets", auth) { m_AssetService = service; + m_RedirectURL = redirectURL; + if (!m_RedirectURL.EndsWith("/")) + m_RedirectURL = m_RedirectURL.TrimEnd('/'); } protected override byte[] ProcessRequest(string path, Stream request, @@ -71,9 +75,10 @@ namespace OpenSim.Server.Handlers.Asset if (p.Length == 0) return result; + string id = string.Empty; if (p.Length > 1) { - string id = p[0]; + id = p[0]; string cmd = p[1]; if (cmd == "data") @@ -124,7 +129,7 @@ namespace OpenSim.Server.Handlers.Asset { // Get the entire asset (metadata + data) - string id = p[0]; + id = p[0]; AssetBase asset = m_AssetService.Get(id); if (asset != null) @@ -151,6 +156,16 @@ namespace OpenSim.Server.Handlers.Asset result = new byte[0]; } + if (httpResponse.StatusCode == (int)HttpStatusCode.NotFound && !string.IsNullOrEmpty(m_RedirectURL) && !string.IsNullOrEmpty(id)) + { + httpResponse.StatusCode = (int)HttpStatusCode.Redirect; + string rurl = m_RedirectURL; + if (!path.StartsWith("/")) + rurl += "/"; + rurl += path; + httpResponse.AddHeader("Location", rurl); + m_log.DebugFormat("[ASSET GET HANDLER]: Asset not found, redirecting to {0} ({1})", rurl, httpResponse.StatusCode); + } return result; } } -- cgit v1.1