aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs
diff options
context:
space:
mode:
authorUbitUmarov2018-11-30 23:10:29 +0000
committerUbitUmarov2018-11-30 23:10:29 +0000
commitb783244a504ae9979c937acef6c18c839de24aa7 (patch)
tree2176b219dc7d5733a4715b9301efac8de0f6790f /OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs
parentadd a sound (diff)
downloadopensim-SC-b783244a504ae9979c937acef6c18c839de24aa7.zip
opensim-SC-b783244a504ae9979c937acef6c18c839de24aa7.tar.gz
opensim-SC-b783244a504ae9979c937acef6c18c839de24aa7.tar.bz2
opensim-SC-b783244a504ae9979c937acef6c18c839de24aa7.tar.xz
move http range parser to util
Diffstat (limited to '')
-rw-r--r--OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs28
1 files changed, 5 insertions, 23 deletions
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
101 return responsedata; 101 return responsedata;
102 } 102 }
103 103
104 Hashtable headers = new Hashtable();
105 responsedata["headers"] = headers;
106
107 string range = String.Empty; 104 string range = String.Empty;
108 105
109 if (((Hashtable)request["headers"])["range"] != null) 106 if (((Hashtable)request["headers"])["range"] != null)
@@ -111,18 +108,18 @@ namespace OpenSim.Capabilities.Handlers
111 else if (((Hashtable)request["headers"])["Range"] != null) 108 else if (((Hashtable)request["headers"])["Range"] != null)
112 range = (string)((Hashtable)request["headers"])["Range"]; 109 range = (string)((Hashtable)request["headers"])["Range"];
113 110
111 responsedata["content_type"] = "application/vnd.ll.mesh";
114 if (String.IsNullOrEmpty(range)) 112 if (String.IsNullOrEmpty(range))
115 { 113 {
116 // full mesh 114 // full mesh
117 responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); 115 responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data);
118 responsedata["content_type"] = "application/vnd.ll.mesh";
119 responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.OK; 116 responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.OK;
120 return responsedata; 117 return responsedata;
121 } 118 }
122 119
123 // range request 120 // range request
124 int start, end; 121 int start, end;
125 if (TryParseRange(range, out start, out end)) 122 if (Util.TryParseHttpRange(range, out start, out end))
126 { 123 {
127 // Before clamping start make sure we can satisfy it in order to avoid 124 // Before clamping start make sure we can satisfy it in order to avoid
128 // sending back the last byte instead of an error status 125 // sending back the last byte instead of an error status
@@ -137,8 +134,10 @@ namespace OpenSim.Capabilities.Handlers
137 int len = end - start + 1; 134 int len = end - start + 1;
138 135
139 //m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID); 136 //m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID);
140 responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.PartialContent; 137 Hashtable headers = new Hashtable();
141 headers["Content-Range"] = String.Format("bytes {0}-{1}/{2}", start, end, mesh.Data.Length); 138 headers["Content-Range"] = String.Format("bytes {0}-{1}/{2}", start, end, mesh.Data.Length);
139 responsedata["headers"] = headers;
140 responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.PartialContent;
142 141
143 byte[] d = new byte[len]; 142 byte[] d = new byte[len];
144 Array.Copy(mesh.Data, start, d, 0, len); 143 Array.Copy(mesh.Data, start, d, 0, len);
@@ -149,25 +148,8 @@ namespace OpenSim.Capabilities.Handlers
149 148
150 m_log.Warn("[GETMESH]: Failed to parse a range from GetMesh request, sending full asset: " + (string)request["uri"]); 149 m_log.Warn("[GETMESH]: Failed to parse a range from GetMesh request, sending full asset: " + (string)request["uri"]);
151 responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); 150 responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data);
152 responsedata["content_type"] = "application/vnd.ll.mesh";
153 responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.OK; 151 responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.OK;
154 return responsedata; 152 return responsedata;
155 } 153 }
156
157 private bool TryParseRange(string header, out int start, out int end)
158 {
159 if (header.StartsWith("bytes="))
160 {
161 string[] rangeValues = header.Substring(6).Split('-');
162 if (rangeValues.Length == 2)
163 {
164 if (Int32.TryParse(rangeValues[0], out start) && Int32.TryParse(rangeValues[1], out end))
165 return true;
166 }
167 }
168
169 start = end = 0;
170 return false;
171 }
172 } 154 }
173} \ No newline at end of file 155} \ No newline at end of file