Adds an optional redirect URL to the asset server handler for when assets are not found locally.
parent
5aeaa7fcdd
commit
449548d7a4
|
@ -70,6 +70,8 @@ namespace OpenSim.Server.Handlers.Asset
|
||||||
bool allowDelete = serverConfig.GetBoolean("AllowRemoteDelete", false);
|
bool allowDelete = serverConfig.GetBoolean("AllowRemoteDelete", false);
|
||||||
bool allowDeleteAllTypes = serverConfig.GetBoolean("AllowRemoteDeleteAllTypes", false);
|
bool allowDeleteAllTypes = serverConfig.GetBoolean("AllowRemoteDeleteAllTypes", false);
|
||||||
|
|
||||||
|
string redirectURL = serverConfig.GetString("RedirectURL", string.Empty);
|
||||||
|
|
||||||
AllowedRemoteDeleteTypes allowedRemoteDeleteTypes;
|
AllowedRemoteDeleteTypes allowedRemoteDeleteTypes;
|
||||||
|
|
||||||
if (!allowDelete)
|
if (!allowDelete)
|
||||||
|
@ -86,7 +88,7 @@ namespace OpenSim.Server.Handlers.Asset
|
||||||
|
|
||||||
IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
|
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 AssetServerPostHandler(m_AssetService, auth));
|
||||||
server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowedRemoteDeleteTypes, auth));
|
server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowedRemoteDeleteTypes, auth));
|
||||||
server.AddStreamHandler(new AssetsExistHandler(m_AssetService));
|
server.AddStreamHandler(new AssetsExistHandler(m_AssetService));
|
||||||
|
|
|
@ -48,6 +48,7 @@ namespace OpenSim.Server.Handlers.Asset
|
||||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
private IAssetService m_AssetService;
|
private IAssetService m_AssetService;
|
||||||
|
private string m_RedirectURL;
|
||||||
|
|
||||||
public AssetServerGetHandler(IAssetService service) :
|
public AssetServerGetHandler(IAssetService service) :
|
||||||
base("GET", "/assets")
|
base("GET", "/assets")
|
||||||
|
@ -55,10 +56,13 @@ namespace OpenSim.Server.Handlers.Asset
|
||||||
m_AssetService = service;
|
m_AssetService = service;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AssetServerGetHandler(IAssetService service, IServiceAuth auth) :
|
public AssetServerGetHandler(IAssetService service, IServiceAuth auth, string redirectURL) :
|
||||||
base("GET", "/assets", auth)
|
base("GET", "/assets", auth)
|
||||||
{
|
{
|
||||||
m_AssetService = service;
|
m_AssetService = service;
|
||||||
|
m_RedirectURL = redirectURL;
|
||||||
|
if (!m_RedirectURL.EndsWith("/"))
|
||||||
|
m_RedirectURL = m_RedirectURL.TrimEnd('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override byte[] ProcessRequest(string path, Stream request,
|
protected override byte[] ProcessRequest(string path, Stream request,
|
||||||
|
@ -71,9 +75,10 @@ namespace OpenSim.Server.Handlers.Asset
|
||||||
if (p.Length == 0)
|
if (p.Length == 0)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
string id = string.Empty;
|
||||||
if (p.Length > 1)
|
if (p.Length > 1)
|
||||||
{
|
{
|
||||||
string id = p[0];
|
id = p[0];
|
||||||
string cmd = p[1];
|
string cmd = p[1];
|
||||||
|
|
||||||
if (cmd == "data")
|
if (cmd == "data")
|
||||||
|
@ -124,7 +129,7 @@ namespace OpenSim.Server.Handlers.Asset
|
||||||
{
|
{
|
||||||
// Get the entire asset (metadata + data)
|
// Get the entire asset (metadata + data)
|
||||||
|
|
||||||
string id = p[0];
|
id = p[0];
|
||||||
AssetBase asset = m_AssetService.Get(id);
|
AssetBase asset = m_AssetService.Get(id);
|
||||||
|
|
||||||
if (asset != null)
|
if (asset != null)
|
||||||
|
@ -151,6 +156,16 @@ namespace OpenSim.Server.Handlers.Asset
|
||||||
result = new byte[0];
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue