aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Capabilities/Handlers/GetTexture/GetTextureRobustHandler.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Capabilities/Handlers/GetTexture/GetTextureRobustHandler.cs99
1 files changed, 31 insertions, 68 deletions
diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureRobustHandler.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureRobustHandler.cs
index c339ec5..0685c5e 100644
--- a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureRobustHandler.cs
+++ b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureRobustHandler.cs
@@ -131,87 +131,50 @@ namespace OpenSim.Capabilities.Handlers
131 /// <returns>False for "caller try another codec"; true otherwise</returns> 131 /// <returns>False for "caller try another codec"; true otherwise</returns>
132 private bool FetchTexture(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, UUID textureID, string format) 132 private bool FetchTexture(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, UUID textureID, string format)
133 { 133 {
134// m_log.DebugFormat("[GETTEXTURE]: {0} with requested format {1}", textureID, format); 134 // m_log.DebugFormat("[GETTEXTURE]: {0} with requested format {1}", textureID, format);
135 AssetBase texture; 135 AssetBase texture;
136 136
137 string fullID = textureID.ToString(); 137 if(!String.IsNullOrEmpty(m_RedirectURL))
138 if (format != DefaultFormat)
139 fullID = fullID + "-" + format;
140
141 if (!String.IsNullOrEmpty(m_RedirectURL))
142 { 138 {
143 // Only try to fetch locally cached textures. Misses are redirected 139 string textureUrl = m_RedirectURL + "?texture_id=" + textureID.ToString();
144 texture = m_assetService.GetCached(fullID); 140 m_log.Debug("[GETTEXTURE]: Redirecting texture request to " + textureUrl);
145 141 httpResponse.StatusCode = (int)OSHttpStatusCode.RedirectMovedPermanently;
146 if (texture != null) 142 httpResponse.RedirectLocation = textureUrl;
143 return true;
144 }
145 else // no redirect
146 {
147 texture = m_assetService.Get(textureID.ToString());
148 if(texture != null)
147 { 149 {
148 if (texture.Type != (sbyte)AssetType.Texture) 150 if(texture.Type != (sbyte)AssetType.Texture)
149 { 151 {
150 httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; 152 httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
151 return true; 153 return true;
152 } 154 }
153 WriteTextureData(httpRequest, httpResponse, texture, format); 155 if(format == DefaultFormat)
154 return true;
155 }
156 else
157 {
158 string textureUrl = m_RedirectURL + "?texture_id="+ textureID.ToString();
159 m_log.Debug("[GETTEXTURE]: Redirecting texture request to " + textureUrl);
160 httpResponse.StatusCode = (int)OSHttpStatusCode.RedirectMovedPermanently;
161 httpResponse.RedirectLocation = textureUrl;
162 return true;
163 }
164 }
165 else // no redirect
166 {
167 // try the cache
168 texture = m_assetService.GetCached(fullID);
169
170 if (texture == null)
171 {
172// m_log.DebugFormat("[GETTEXTURE]: texture was not in the cache");
173
174 // Fetch locally or remotely. Misses return a 404
175 texture = m_assetService.Get(textureID.ToString());
176
177 if (texture != null)
178 { 156 {
179 if (texture.Type != (sbyte)AssetType.Texture) 157 WriteTextureData(httpRequest, httpResponse, texture, format);
180 { 158 return true;
181 httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
182 return true;
183 }
184 if (format == DefaultFormat)
185 {
186 WriteTextureData(httpRequest, httpResponse, texture, format);
187 return true;
188 }
189 else
190 {
191 AssetBase newTexture = new AssetBase(texture.ID + "-" + format, texture.Name, (sbyte)AssetType.Texture, texture.Metadata.CreatorID);
192 newTexture.Data = ConvertTextureData(texture, format);
193 if (newTexture.Data.Length == 0)
194 return false; // !!! Caller try another codec, please!
195
196 newTexture.Flags = AssetFlags.Collectable;
197 newTexture.Temporary = true;
198 newTexture.Local = true;
199 m_assetService.Store(newTexture);
200 WriteTextureData(httpRequest, httpResponse, newTexture, format);
201 return true;
202 }
203 } 159 }
204 } 160 else
205 else // it was on the cache 161 {
206 { 162 AssetBase newTexture = new AssetBase(texture.ID + "-" + format, texture.Name, (sbyte)AssetType.Texture, texture.Metadata.CreatorID);
207// m_log.DebugFormat("[GETTEXTURE]: texture was in the cache"); 163 newTexture.Data = ConvertTextureData(texture, format);
208 WriteTextureData(httpRequest, httpResponse, texture, format); 164 if(newTexture.Data.Length == 0)
209 return true; 165 return false; // !!! Caller try another codec, please!
210 } 166
167 newTexture.Flags = AssetFlags.Collectable;
168 newTexture.Temporary = true;
169 newTexture.Local = true;
170 WriteTextureData(httpRequest, httpResponse, newTexture, format);
171 return true;
172 }
173 }
211 } 174 }
212 175
213 // not found 176 // not found
214// m_log.Warn("[GETTEXTURE]: Texture " + textureID + " not found"); 177 // m_log.Warn("[GETTEXTURE]: Texture " + textureID + " not found");
215 httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; 178 httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
216 return true; 179 return true;
217 } 180 }