From acc01bb85d5c5f15a3943a908433b7fe08075c93 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 6 Dec 2012 01:12:12 +0000 Subject: [PATCH] Allow GetTexture calls with no second value in the range header (e.g. just 5333-) It looks like the latest Kokua is doing this. As per http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html, leaving off the second value is legal This indicates the caller wants the rest of the entity. --- .../Handlers/GetTexture/GetTextureHandler.cs | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs index 04cc33aa51..6e9094a84a 100644 --- a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs +++ b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs @@ -246,6 +246,11 @@ namespace OpenSim.Capabilities.Handlers } else { + // Handle the case where no second range value was given. This is equivalent to requesting + // the rest of the entity. + if (end == -1) + end = int.MaxValue; + end = Utils.Clamp(end, 0, texture.Data.Length - 1); start = Utils.Clamp(start, 0, end); int len = end - start + 1; @@ -299,15 +304,43 @@ namespace OpenSim.Capabilities.Handlers // texture.FullID, range, response.StatusCode, response.ContentLength, texture.Data.Length); } + /// + /// Parse a range header. + /// + /// + /// As per http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html, + /// this obeys range headers with two values (e.g. 533-4165) and no second value (e.g. 533-). + /// Where there is no value, -1 is returned. + /// FIXME: Need to cover the case where only a second value is specified (e.g. -4165), probably by returning -1 + /// for start. + /// + /// + /// Undefined if the parse fails. + /// Undefined if the parse fails. private bool TryParseRange(string header, out int start, out int end) { + start = end = 0; + if (header.StartsWith("bytes=")) { string[] rangeValues = header.Substring(6).Split('-'); + if (rangeValues.Length == 2) { - if (Int32.TryParse(rangeValues[0], out start) && Int32.TryParse(rangeValues[1], out end)) + if (!Int32.TryParse(rangeValues[0], out start)) + return false; + + string rawEnd = rangeValues[1]; + + if (rawEnd == "") + { + end = -1; return true; + } + else if (Int32.TryParse(rawEnd, out end)) + { + return true; + } } }