mantis 7885: robust asset services have no cache and only accept a asset ID that is a uuid, so regions hack to cache several image formats is not possible. Robut GetTexture is very heavy unless image format is the default (j2k mime type x-j2k), since with no cache image convertions is performed on every request. Adicionally it does expose all textures if the tcp port is public. Avoid using it.
parent
8c390ef3fe
commit
a0d0d65c70
|
@ -131,87 +131,50 @@ namespace OpenSim.Capabilities.Handlers
|
||||||
/// <returns>False for "caller try another codec"; true otherwise</returns>
|
/// <returns>False for "caller try another codec"; true otherwise</returns>
|
||||||
private bool FetchTexture(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, UUID textureID, string format)
|
private bool FetchTexture(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, UUID textureID, string format)
|
||||||
{
|
{
|
||||||
// m_log.DebugFormat("[GETTEXTURE]: {0} with requested format {1}", textureID, format);
|
// m_log.DebugFormat("[GETTEXTURE]: {0} with requested format {1}", textureID, format);
|
||||||
AssetBase texture;
|
AssetBase texture;
|
||||||
|
|
||||||
string fullID = textureID.ToString();
|
if(!String.IsNullOrEmpty(m_RedirectURL))
|
||||||
if (format != DefaultFormat)
|
|
||||||
fullID = fullID + "-" + format;
|
|
||||||
|
|
||||||
if (!String.IsNullOrEmpty(m_RedirectURL))
|
|
||||||
{
|
{
|
||||||
// Only try to fetch locally cached textures. Misses are redirected
|
string textureUrl = m_RedirectURL + "?texture_id=" + textureID.ToString();
|
||||||
texture = m_assetService.GetCached(fullID);
|
m_log.Debug("[GETTEXTURE]: Redirecting texture request to " + textureUrl);
|
||||||
|
httpResponse.StatusCode = (int)OSHttpStatusCode.RedirectMovedPermanently;
|
||||||
if (texture != null)
|
httpResponse.RedirectLocation = textureUrl;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else // no redirect
|
||||||
|
{
|
||||||
|
texture = m_assetService.Get(textureID.ToString());
|
||||||
|
if(texture != null)
|
||||||
{
|
{
|
||||||
if (texture.Type != (sbyte)AssetType.Texture)
|
if(texture.Type != (sbyte)AssetType.Texture)
|
||||||
{
|
{
|
||||||
httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
|
httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
WriteTextureData(httpRequest, httpResponse, texture, format);
|
if(format == DefaultFormat)
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
string textureUrl = m_RedirectURL + "?texture_id="+ textureID.ToString();
|
|
||||||
m_log.Debug("[GETTEXTURE]: Redirecting texture request to " + textureUrl);
|
|
||||||
httpResponse.StatusCode = (int)OSHttpStatusCode.RedirectMovedPermanently;
|
|
||||||
httpResponse.RedirectLocation = textureUrl;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else // no redirect
|
|
||||||
{
|
|
||||||
// try the cache
|
|
||||||
texture = m_assetService.GetCached(fullID);
|
|
||||||
|
|
||||||
if (texture == null)
|
|
||||||
{
|
|
||||||
// m_log.DebugFormat("[GETTEXTURE]: texture was not in the cache");
|
|
||||||
|
|
||||||
// Fetch locally or remotely. Misses return a 404
|
|
||||||
texture = m_assetService.Get(textureID.ToString());
|
|
||||||
|
|
||||||
if (texture != null)
|
|
||||||
{
|
{
|
||||||
if (texture.Type != (sbyte)AssetType.Texture)
|
WriteTextureData(httpRequest, httpResponse, texture, format);
|
||||||
{
|
return true;
|
||||||
httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (format == DefaultFormat)
|
|
||||||
{
|
|
||||||
WriteTextureData(httpRequest, httpResponse, texture, format);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
AssetBase newTexture = new AssetBase(texture.ID + "-" + format, texture.Name, (sbyte)AssetType.Texture, texture.Metadata.CreatorID);
|
|
||||||
newTexture.Data = ConvertTextureData(texture, format);
|
|
||||||
if (newTexture.Data.Length == 0)
|
|
||||||
return false; // !!! Caller try another codec, please!
|
|
||||||
|
|
||||||
newTexture.Flags = AssetFlags.Collectable;
|
|
||||||
newTexture.Temporary = true;
|
|
||||||
newTexture.Local = true;
|
|
||||||
m_assetService.Store(newTexture);
|
|
||||||
WriteTextureData(httpRequest, httpResponse, newTexture, format);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else // it was on the cache
|
{
|
||||||
{
|
AssetBase newTexture = new AssetBase(texture.ID + "-" + format, texture.Name, (sbyte)AssetType.Texture, texture.Metadata.CreatorID);
|
||||||
// m_log.DebugFormat("[GETTEXTURE]: texture was in the cache");
|
newTexture.Data = ConvertTextureData(texture, format);
|
||||||
WriteTextureData(httpRequest, httpResponse, texture, format);
|
if(newTexture.Data.Length == 0)
|
||||||
return true;
|
return false; // !!! Caller try another codec, please!
|
||||||
}
|
|
||||||
|
newTexture.Flags = AssetFlags.Collectable;
|
||||||
|
newTexture.Temporary = true;
|
||||||
|
newTexture.Local = true;
|
||||||
|
WriteTextureData(httpRequest, httpResponse, newTexture, format);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// not found
|
// not found
|
||||||
// m_log.Warn("[GETTEXTURE]: Texture " + textureID + " not found");
|
// m_log.Warn("[GETTEXTURE]: Texture " + textureID + " not found");
|
||||||
httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
|
httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue