Adds an optional redirect URL to the asset server handler for when assets are not found locally.

bullet-2.82
Diva Canto 2014-05-26 08:13:49 -07:00
parent 5aeaa7fcdd
commit 449548d7a4
2 changed files with 21 additions and 4 deletions

View File

@ -70,6 +70,8 @@ namespace OpenSim.Server.Handlers.Asset
bool allowDelete = serverConfig.GetBoolean("AllowRemoteDelete", false);
bool allowDeleteAllTypes = serverConfig.GetBoolean("AllowRemoteDeleteAllTypes", false);
string redirectURL = serverConfig.GetString("RedirectURL", string.Empty);
AllowedRemoteDeleteTypes allowedRemoteDeleteTypes;
if (!allowDelete)
@ -86,7 +88,7 @@ namespace OpenSim.Server.Handlers.Asset
IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
server.AddStreamHandler(new AssetServerGetHandler(m_AssetService, auth));
server.AddStreamHandler(new AssetServerGetHandler(m_AssetService, auth, redirectURL));
server.AddStreamHandler(new AssetServerPostHandler(m_AssetService, auth));
server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowedRemoteDeleteTypes, auth));
server.AddStreamHandler(new AssetsExistHandler(m_AssetService));

View File

@ -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;
}
}