aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Capabilities
diff options
context:
space:
mode:
authorUbitUmarov2018-11-30 23:10:29 +0000
committerUbitUmarov2018-11-30 23:10:29 +0000
commitb783244a504ae9979c937acef6c18c839de24aa7 (patch)
tree2176b219dc7d5733a4715b9301efac8de0f6790f /OpenSim/Capabilities
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 'OpenSim/Capabilities')
-rw-r--r--OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs28
-rw-r--r--OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs46
2 files changed, 6 insertions, 68 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
diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs
index 57ec2f5..51332bc 100644
--- a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs
+++ b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs
@@ -210,7 +210,7 @@ namespace OpenSim.Capabilities.Handlers
210 { 210 {
211 // Range request 211 // Range request
212 int start, end; 212 int start, end;
213 if (TryParseRange(range, out start, out end)) 213 if (Util.TryParseHttpRange(range, out start, out end))
214 { 214 {
215 // Before clamping start make sure we can satisfy it in order to avoid 215 // Before clamping start make sure we can satisfy it in order to avoid
216 // sending back the last byte instead of an error status 216 // sending back the last byte instead of an error status
@@ -289,50 +289,6 @@ namespace OpenSim.Capabilities.Handlers
289// texture.FullID, range, response.StatusCode, response.ContentLength, texture.Data.Length); 289// texture.FullID, range, response.StatusCode, response.ContentLength, texture.Data.Length);
290 } 290 }
291 291
292 /// <summary>
293 /// Parse a range header.
294 /// </summary>
295 /// <remarks>
296 /// As per http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html,
297 /// this obeys range headers with two values (e.g. 533-4165) and no second value (e.g. 533-).
298 /// Where there is no value, -1 is returned.
299 /// FIXME: Need to cover the case where only a second value is specified (e.g. -4165), probably by returning -1
300 /// for start.</remarks>
301 /// <returns></returns>
302 /// <param name='header'></param>
303 /// <param name='start'>Start of the range. Undefined if this was not a number.</param>
304 /// <param name='end'>End of the range. Will be -1 if no end specified. Undefined if there was a raw string but this was not a number.</param>
305 private bool TryParseRange(string header, out int start, out int end)
306 {
307 start = end = 0;
308
309 if (header.StartsWith("bytes="))
310 {
311 string[] rangeValues = header.Substring(6).Split('-');
312
313 if (rangeValues.Length == 2)
314 {
315 if (!Int32.TryParse(rangeValues[0], out start))
316 return false;
317
318 string rawEnd = rangeValues[1];
319
320 if (rawEnd == "")
321 {
322 end = -1;
323 return true;
324 }
325 else if (Int32.TryParse(rawEnd, out end))
326 {
327 return true;
328 }
329 }
330 }
331
332 start = end = 0;
333 return false;
334 }
335
336 private byte[] ConvertTextureData(AssetBase texture, string format) 292 private byte[] ConvertTextureData(AssetBase texture, string format)
337 { 293 {
338 m_log.DebugFormat("[GETTEXTURE]: Converting texture {0} to {1}", texture.ID, format); 294 m_log.DebugFormat("[GETTEXTURE]: Converting texture {0} to {1}", texture.ID, format);