From b783244a504ae9979c937acef6c18c839de24aa7 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Fri, 30 Nov 2018 23:10:29 +0000 Subject: move http range parser to util --- .../Handlers/GetMesh/GetMeshHandler.cs | 28 ++++------------------ 1 file changed, 5 insertions(+), 23 deletions(-) (limited to 'OpenSim/Capabilities/Handlers/GetMesh') diff --git a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs index ed42efe..a76112f 100644 --- a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs +++ b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs @@ -101,9 +101,6 @@ namespace OpenSim.Capabilities.Handlers return responsedata; } - Hashtable headers = new Hashtable(); - responsedata["headers"] = headers; - string range = String.Empty; if (((Hashtable)request["headers"])["range"] != null) @@ -111,18 +108,18 @@ namespace OpenSim.Capabilities.Handlers else if (((Hashtable)request["headers"])["Range"] != null) range = (string)((Hashtable)request["headers"])["Range"]; + responsedata["content_type"] = "application/vnd.ll.mesh"; if (String.IsNullOrEmpty(range)) { // full mesh responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); - responsedata["content_type"] = "application/vnd.ll.mesh"; responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.OK; return responsedata; } // range request int start, end; - if (TryParseRange(range, out start, out end)) + if (Util.TryParseHttpRange(range, out start, out end)) { // Before clamping start make sure we can satisfy it in order to avoid // sending back the last byte instead of an error status @@ -137,8 +134,10 @@ namespace OpenSim.Capabilities.Handlers int len = end - start + 1; //m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID); - responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.PartialContent; + Hashtable headers = new Hashtable(); headers["Content-Range"] = String.Format("bytes {0}-{1}/{2}", start, end, mesh.Data.Length); + responsedata["headers"] = headers; + responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.PartialContent; byte[] d = new byte[len]; Array.Copy(mesh.Data, start, d, 0, len); @@ -149,25 +148,8 @@ namespace OpenSim.Capabilities.Handlers m_log.Warn("[GETMESH]: Failed to parse a range from GetMesh request, sending full asset: " + (string)request["uri"]); responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); - responsedata["content_type"] = "application/vnd.ll.mesh"; responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.OK; return responsedata; } - - private bool TryParseRange(string header, out int start, out int end) - { - 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)) - return true; - } - } - - start = end = 0; - return false; - } } } \ No newline at end of file -- cgit v1.1