aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs')
-rw-r--r--OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs35
1 files changed, 34 insertions, 1 deletions
diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs
index 04cc33a..6e9094a 100644
--- a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs
+++ b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs
@@ -246,6 +246,11 @@ namespace OpenSim.Capabilities.Handlers
246 } 246 }
247 else 247 else
248 { 248 {
249 // Handle the case where no second range value was given. This is equivalent to requesting
250 // the rest of the entity.
251 if (end == -1)
252 end = int.MaxValue;
253
249 end = Utils.Clamp(end, 0, texture.Data.Length - 1); 254 end = Utils.Clamp(end, 0, texture.Data.Length - 1);
250 start = Utils.Clamp(start, 0, end); 255 start = Utils.Clamp(start, 0, end);
251 int len = end - start + 1; 256 int len = end - start + 1;
@@ -299,15 +304,43 @@ namespace OpenSim.Capabilities.Handlers
299// texture.FullID, range, response.StatusCode, response.ContentLength, texture.Data.Length); 304// texture.FullID, range, response.StatusCode, response.ContentLength, texture.Data.Length);
300 } 305 }
301 306
307 /// <summary>
308 /// Parse a range header.
309 /// </summary>
310 /// <remarks>
311 /// As per http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html,
312 /// this obeys range headers with two values (e.g. 533-4165) and no second value (e.g. 533-).
313 /// Where there is no value, -1 is returned.
314 /// FIXME: Need to cover the case where only a second value is specified (e.g. -4165), probably by returning -1
315 /// for start.</remarks>
316 /// <returns></returns>
317 /// <param name='header'></param>
318 /// <param name='start'>Undefined if the parse fails.</param>
319 /// <param name='end'>Undefined if the parse fails.</param>
302 private bool TryParseRange(string header, out int start, out int end) 320 private bool TryParseRange(string header, out int start, out int end)
303 { 321 {
322 start = end = 0;
323
304 if (header.StartsWith("bytes=")) 324 if (header.StartsWith("bytes="))
305 { 325 {
306 string[] rangeValues = header.Substring(6).Split('-'); 326 string[] rangeValues = header.Substring(6).Split('-');
327
307 if (rangeValues.Length == 2) 328 if (rangeValues.Length == 2)
308 { 329 {
309 if (Int32.TryParse(rangeValues[0], out start) && Int32.TryParse(rangeValues[1], out end)) 330 if (!Int32.TryParse(rangeValues[0], out start))
331 return false;
332
333 string rawEnd = rangeValues[1];
334
335 if (rawEnd == "")
336 {
337 end = -1;
338 return true;
339 }
340 else if (Int32.TryParse(rawEnd, out end))
341 {
310 return true; 342 return true;
343 }
311 } 344 }
312 } 345 }
313 346