diff options
Diffstat (limited to 'OpenSim/Capabilities/Handlers')
4 files changed, 253 insertions, 116 deletions
diff --git a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs index 720640e..380705f 100644 --- a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs +++ b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs | |||
@@ -45,16 +45,53 @@ namespace OpenSim.Capabilities.Handlers | |||
45 | { | 45 | { |
46 | public class GetMeshHandler | 46 | public class GetMeshHandler |
47 | { | 47 | { |
48 | // private static readonly ILog m_log = | 48 | private static readonly ILog m_log = |
49 | // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 49 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
50 | 50 | ||
51 | private IAssetService m_assetService; | 51 | private IAssetService m_assetService; |
52 | 52 | ||
53 | public const string DefaultFormat = "vnd.ll.mesh"; | ||
54 | |||
53 | public GetMeshHandler(IAssetService assService) | 55 | public GetMeshHandler(IAssetService assService) |
54 | { | 56 | { |
55 | m_assetService = assService; | 57 | m_assetService = assService; |
56 | } | 58 | } |
59 | public Hashtable Handle(Hashtable request) | ||
60 | { | ||
61 | Hashtable ret = new Hashtable(); | ||
62 | ret["int_response_code"] = (int)System.Net.HttpStatusCode.NotFound; | ||
63 | ret["content_type"] = "text/plain"; | ||
64 | ret["keepalive"] = false; | ||
65 | ret["reusecontext"] = false; | ||
66 | ret["int_bytes"] = 0; | ||
67 | string MeshStr = (string)request["mesh_id"]; | ||
68 | |||
69 | |||
70 | //m_log.DebugFormat("[GETMESH]: called {0}", MeshStr); | ||
71 | |||
72 | if (m_assetService == null) | ||
73 | { | ||
74 | m_log.Error("[GETMESH]: Cannot fetch mesh " + MeshStr + " without an asset service"); | ||
75 | } | ||
76 | |||
77 | UUID meshID; | ||
78 | if (!String.IsNullOrEmpty(MeshStr) && UUID.TryParse(MeshStr, out meshID)) | ||
79 | { | ||
80 | // m_log.DebugFormat("[GETMESH]: Received request for mesh id {0}", meshID); | ||
57 | 81 | ||
82 | |||
83 | ret = ProcessGetMesh(request, UUID.Zero, null); | ||
84 | |||
85 | |||
86 | } | ||
87 | else | ||
88 | { | ||
89 | m_log.Warn("[GETMESH]: Failed to parse a mesh_id from GetMesh request: " + (string)request["uri"]); | ||
90 | } | ||
91 | |||
92 | |||
93 | return ret; | ||
94 | } | ||
58 | public Hashtable ProcessGetMesh(Hashtable request, UUID AgentId, Caps cap) | 95 | public Hashtable ProcessGetMesh(Hashtable request, UUID AgentId, Caps cap) |
59 | { | 96 | { |
60 | Hashtable responsedata = new Hashtable(); | 97 | Hashtable responsedata = new Hashtable(); |
@@ -62,6 +99,7 @@ namespace OpenSim.Capabilities.Handlers | |||
62 | responsedata["content_type"] = "text/plain"; | 99 | responsedata["content_type"] = "text/plain"; |
63 | responsedata["keepalive"] = false; | 100 | responsedata["keepalive"] = false; |
64 | responsedata["str_response_string"] = "Request wasn't what was expected"; | 101 | responsedata["str_response_string"] = "Request wasn't what was expected"; |
102 | responsedata["reusecontext"] = false; | ||
65 | 103 | ||
66 | string meshStr = string.Empty; | 104 | string meshStr = string.Empty; |
67 | 105 | ||
@@ -77,6 +115,7 @@ namespace OpenSim.Capabilities.Handlers | |||
77 | responsedata["content_type"] = "text/plain"; | 115 | responsedata["content_type"] = "text/plain"; |
78 | responsedata["keepalive"] = false; | 116 | responsedata["keepalive"] = false; |
79 | responsedata["str_response_string"] = "The asset service is unavailable. So is your mesh."; | 117 | responsedata["str_response_string"] = "The asset service is unavailable. So is your mesh."; |
118 | responsedata["reusecontext"] = false; | ||
80 | return responsedata; | 119 | return responsedata; |
81 | } | 120 | } |
82 | 121 | ||
@@ -86,9 +125,100 @@ namespace OpenSim.Capabilities.Handlers | |||
86 | { | 125 | { |
87 | if (mesh.Type == (SByte)AssetType.Mesh) | 126 | if (mesh.Type == (SByte)AssetType.Mesh) |
88 | { | 127 | { |
89 | responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); | 128 | |
90 | responsedata["content_type"] = "application/vnd.ll.mesh"; | 129 | Hashtable headers = new Hashtable(); |
91 | responsedata["int_response_code"] = 200; | 130 | responsedata["headers"] = headers; |
131 | |||
132 | string range = String.Empty; | ||
133 | |||
134 | if (((Hashtable)request["headers"])["range"] != null) | ||
135 | range = (string)((Hashtable)request["headers"])["range"]; | ||
136 | |||
137 | else if (((Hashtable)request["headers"])["Range"] != null) | ||
138 | range = (string)((Hashtable)request["headers"])["Range"]; | ||
139 | |||
140 | if (!String.IsNullOrEmpty(range)) // Mesh Asset LOD // Physics | ||
141 | { | ||
142 | // Range request | ||
143 | int start, end; | ||
144 | if (TryParseRange(range, out start, out end)) | ||
145 | { | ||
146 | // Before clamping start make sure we can satisfy it in order to avoid | ||
147 | // sending back the last byte instead of an error status | ||
148 | if (start >= mesh.Data.Length) | ||
149 | { | ||
150 | responsedata["int_response_code"] = 404; //501; //410; //404; | ||
151 | responsedata["content_type"] = "text/plain"; | ||
152 | responsedata["keepalive"] = false; | ||
153 | responsedata["str_response_string"] = "This range doesnt exist."; | ||
154 | responsedata["reusecontext"] = false; | ||
155 | responsedata["int_lod"] = 3; | ||
156 | return responsedata; | ||
157 | } | ||
158 | else | ||
159 | { | ||
160 | end = Utils.Clamp(end, 0, mesh.Data.Length - 1); | ||
161 | start = Utils.Clamp(start, 0, end); | ||
162 | int len = end - start + 1; | ||
163 | |||
164 | //m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID); | ||
165 | |||
166 | if (start > 20000) | ||
167 | { | ||
168 | responsedata["int_lod"] = 3; | ||
169 | } | ||
170 | else if (start < 4097) | ||
171 | { | ||
172 | responsedata["int_lod"] = 1; | ||
173 | } | ||
174 | else | ||
175 | { | ||
176 | responsedata["int_lod"] = 2; | ||
177 | } | ||
178 | |||
179 | |||
180 | if (start == 0 && len == mesh.Data.Length) // well redudante maybe | ||
181 | { | ||
182 | responsedata["int_response_code"] = (int) System.Net.HttpStatusCode.OK; | ||
183 | responsedata["bin_response_data"] = mesh.Data; | ||
184 | responsedata["int_bytes"] = mesh.Data.Length; | ||
185 | responsedata["reusecontext"] = false; | ||
186 | responsedata["int_lod"] = 3; | ||
187 | |||
188 | } | ||
189 | else | ||
190 | { | ||
191 | responsedata["int_response_code"] = | ||
192 | (int) System.Net.HttpStatusCode.PartialContent; | ||
193 | headers["Content-Range"] = String.Format("bytes {0}-{1}/{2}", start, end, | ||
194 | mesh.Data.Length); | ||
195 | |||
196 | byte[] d = new byte[len]; | ||
197 | Array.Copy(mesh.Data, start, d, 0, len); | ||
198 | responsedata["bin_response_data"] = d; | ||
199 | responsedata["int_bytes"] = len; | ||
200 | responsedata["reusecontext"] = false; | ||
201 | } | ||
202 | } | ||
203 | } | ||
204 | else | ||
205 | { | ||
206 | m_log.Warn("[GETMESH]: Failed to parse a range from GetMesh request, sending full asset: " + (string)request["uri"]); | ||
207 | responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); | ||
208 | responsedata["content_type"] = "application/vnd.ll.mesh"; | ||
209 | responsedata["int_response_code"] = 200; | ||
210 | responsedata["reusecontext"] = false; | ||
211 | responsedata["int_lod"] = 3; | ||
212 | } | ||
213 | } | ||
214 | else | ||
215 | { | ||
216 | responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); | ||
217 | responsedata["content_type"] = "application/vnd.ll.mesh"; | ||
218 | responsedata["int_response_code"] = 200; | ||
219 | responsedata["reusecontext"] = false; | ||
220 | responsedata["int_lod"] = 3; | ||
221 | } | ||
92 | } | 222 | } |
93 | // Optionally add additional mesh types here | 223 | // Optionally add additional mesh types here |
94 | else | 224 | else |
@@ -97,6 +227,8 @@ namespace OpenSim.Capabilities.Handlers | |||
97 | responsedata["content_type"] = "text/plain"; | 227 | responsedata["content_type"] = "text/plain"; |
98 | responsedata["keepalive"] = false; | 228 | responsedata["keepalive"] = false; |
99 | responsedata["str_response_string"] = "Unfortunately, this asset isn't a mesh."; | 229 | responsedata["str_response_string"] = "Unfortunately, this asset isn't a mesh."; |
230 | responsedata["reusecontext"] = false; | ||
231 | responsedata["int_lod"] = 1; | ||
100 | return responsedata; | 232 | return responsedata; |
101 | } | 233 | } |
102 | } | 234 | } |
@@ -106,11 +238,28 @@ namespace OpenSim.Capabilities.Handlers | |||
106 | responsedata["content_type"] = "text/plain"; | 238 | responsedata["content_type"] = "text/plain"; |
107 | responsedata["keepalive"] = false; | 239 | responsedata["keepalive"] = false; |
108 | responsedata["str_response_string"] = "Your Mesh wasn't found. Sorry!"; | 240 | responsedata["str_response_string"] = "Your Mesh wasn't found. Sorry!"; |
241 | responsedata["reusecontext"] = false; | ||
242 | responsedata["int_lod"] = 0; | ||
109 | return responsedata; | 243 | return responsedata; |
110 | } | 244 | } |
111 | } | 245 | } |
112 | 246 | ||
113 | return responsedata; | 247 | return responsedata; |
114 | } | 248 | } |
249 | private bool TryParseRange(string header, out int start, out int end) | ||
250 | { | ||
251 | if (header.StartsWith("bytes=")) | ||
252 | { | ||
253 | string[] rangeValues = header.Substring(6).Split('-'); | ||
254 | if (rangeValues.Length == 2) | ||
255 | { | ||
256 | if (Int32.TryParse(rangeValues[0], out start) && Int32.TryParse(rangeValues[1], out end)) | ||
257 | return true; | ||
258 | } | ||
259 | } | ||
260 | |||
261 | start = end = 0; | ||
262 | return false; | ||
263 | } | ||
115 | } | 264 | } |
116 | } \ No newline at end of file | 265 | } \ No newline at end of file |
diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs index 04cc33a..6437d0b 100644 --- a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs +++ b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs | |||
@@ -47,36 +47,36 @@ using Caps = OpenSim.Framework.Capabilities.Caps; | |||
47 | 47 | ||
48 | namespace OpenSim.Capabilities.Handlers | 48 | namespace OpenSim.Capabilities.Handlers |
49 | { | 49 | { |
50 | public class GetTextureHandler : BaseStreamHandler | 50 | public class GetTextureHandler |
51 | { | 51 | { |
52 | private static readonly ILog m_log = | 52 | private static readonly ILog m_log = |
53 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 53 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
54 | |||
54 | private IAssetService m_assetService; | 55 | private IAssetService m_assetService; |
55 | 56 | ||
56 | public const string DefaultFormat = "x-j2c"; | 57 | public const string DefaultFormat = "x-j2c"; |
57 | 58 | ||
58 | // TODO: Change this to a config option | 59 | public GetTextureHandler(IAssetService assService) |
59 | const string REDIRECT_URL = null; | ||
60 | |||
61 | public GetTextureHandler(string path, IAssetService assService, string name, string description) | ||
62 | : base("GET", path, name, description) | ||
63 | { | 60 | { |
64 | m_assetService = assService; | 61 | m_assetService = assService; |
65 | } | 62 | } |
66 | 63 | ||
67 | public override byte[] Handle(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | 64 | public Hashtable Handle(Hashtable request) |
68 | { | 65 | { |
69 | // Try to parse the texture ID from the request URL | 66 | Hashtable ret = new Hashtable(); |
70 | NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); | 67 | ret["int_response_code"] = (int)System.Net.HttpStatusCode.NotFound; |
71 | string textureStr = query.GetOne("texture_id"); | 68 | ret["content_type"] = "text/plain"; |
72 | string format = query.GetOne("format"); | 69 | ret["keepalive"] = false; |
70 | ret["reusecontext"] = false; | ||
71 | ret["int_bytes"] = 0; | ||
72 | string textureStr = (string)request["texture_id"]; | ||
73 | string format = (string)request["format"]; | ||
73 | 74 | ||
74 | //m_log.DebugFormat("[GETTEXTURE]: called {0}", textureStr); | 75 | //m_log.DebugFormat("[GETTEXTURE]: called {0}", textureStr); |
75 | 76 | ||
76 | if (m_assetService == null) | 77 | if (m_assetService == null) |
77 | { | 78 | { |
78 | m_log.Error("[GETTEXTURE]: Cannot fetch texture " + textureStr + " without an asset service"); | 79 | m_log.Error("[GETTEXTURE]: Cannot fetch texture " + textureStr + " without an asset service"); |
79 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
80 | } | 80 | } |
81 | 81 | ||
82 | UUID textureID; | 82 | UUID textureID; |
@@ -91,30 +91,30 @@ namespace OpenSim.Capabilities.Handlers | |||
91 | } | 91 | } |
92 | else | 92 | else |
93 | { | 93 | { |
94 | formats = WebUtil.GetPreferredImageTypes(httpRequest.Headers.Get("Accept")); | 94 | formats = new string[1] { DefaultFormat }; // default |
95 | if (((Hashtable)request["headers"])["Accept"] != null) | ||
96 | formats = WebUtil.GetPreferredImageTypes((string)((Hashtable)request["headers"])["Accept"]); | ||
95 | if (formats.Length == 0) | 97 | if (formats.Length == 0) |
96 | formats = new string[1] { DefaultFormat }; // default | 98 | formats = new string[1] { DefaultFormat }; // default |
97 | 99 | ||
98 | } | 100 | } |
99 | // OK, we have an array with preferred formats, possibly with only one entry | 101 | // OK, we have an array with preferred formats, possibly with only one entry |
100 | 102 | ||
101 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
102 | foreach (string f in formats) | 103 | foreach (string f in formats) |
103 | { | 104 | { |
104 | if (FetchTexture(httpRequest, httpResponse, textureID, f)) | 105 | if (FetchTexture(request, ret, textureID, f)) |
105 | break; | 106 | break; |
106 | } | 107 | } |
107 | } | 108 | } |
108 | else | 109 | else |
109 | { | 110 | { |
110 | m_log.Warn("[GETTEXTURE]: Failed to parse a texture_id from GetTexture request: " + httpRequest.Url); | 111 | m_log.Warn("[GETTEXTURE]: Failed to parse a texture_id from GetTexture request: " + (string)request["uri"]); |
111 | } | 112 | } |
112 | 113 | ||
113 | // m_log.DebugFormat( | 114 | // m_log.DebugFormat( |
114 | // "[GETTEXTURE]: For texture {0} sending back response {1}, data length {2}", | 115 | // "[GETTEXTURE]: For texture {0} sending back response {1}, data length {2}", |
115 | // textureID, httpResponse.StatusCode, httpResponse.ContentLength); | 116 | // textureID, httpResponse.StatusCode, httpResponse.ContentLength); |
116 | 117 | return ret; | |
117 | return null; | ||
118 | } | 118 | } |
119 | 119 | ||
120 | /// <summary> | 120 | /// <summary> |
@@ -125,7 +125,7 @@ namespace OpenSim.Capabilities.Handlers | |||
125 | /// <param name="textureID"></param> | 125 | /// <param name="textureID"></param> |
126 | /// <param name="format"></param> | 126 | /// <param name="format"></param> |
127 | /// <returns>False for "caller try another codec"; true otherwise</returns> | 127 | /// <returns>False for "caller try another codec"; true otherwise</returns> |
128 | private bool FetchTexture(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, UUID textureID, string format) | 128 | private bool FetchTexture(Hashtable request, Hashtable response, UUID textureID, string format) |
129 | { | 129 | { |
130 | // m_log.DebugFormat("[GETTEXTURE]: {0} with requested format {1}", textureID, format); | 130 | // m_log.DebugFormat("[GETTEXTURE]: {0} with requested format {1}", textureID, format); |
131 | AssetBase texture; | 131 | AssetBase texture; |
@@ -134,84 +134,65 @@ namespace OpenSim.Capabilities.Handlers | |||
134 | if (format != DefaultFormat) | 134 | if (format != DefaultFormat) |
135 | fullID = fullID + "-" + format; | 135 | fullID = fullID + "-" + format; |
136 | 136 | ||
137 | if (!String.IsNullOrEmpty(REDIRECT_URL)) | 137 | // try the cache |
138 | texture = m_assetService.GetCached(fullID); | ||
139 | |||
140 | if (texture == null) | ||
138 | { | 141 | { |
139 | // Only try to fetch locally cached textures. Misses are redirected | 142 | //m_log.DebugFormat("[GETTEXTURE]: texture was not in the cache"); |
140 | texture = m_assetService.GetCached(fullID); | 143 | |
144 | // Fetch locally or remotely. Misses return a 404 | ||
145 | texture = m_assetService.Get(textureID.ToString()); | ||
141 | 146 | ||
142 | if (texture != null) | 147 | if (texture != null) |
143 | { | 148 | { |
144 | if (texture.Type != (sbyte)AssetType.Texture) | 149 | if (texture.Type != (sbyte)AssetType.Texture) |
150 | return true; | ||
151 | |||
152 | if (format == DefaultFormat) | ||
145 | { | 153 | { |
146 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | 154 | WriteTextureData(request, response, texture, format); |
147 | return true; | 155 | return true; |
148 | } | 156 | } |
149 | WriteTextureData(httpRequest, httpResponse, texture, format); | 157 | else |
150 | } | ||
151 | else | ||
152 | { | ||
153 | string textureUrl = REDIRECT_URL + textureID.ToString(); | ||
154 | m_log.Debug("[GETTEXTURE]: Redirecting texture request to " + textureUrl); | ||
155 | httpResponse.RedirectLocation = textureUrl; | ||
156 | return true; | ||
157 | } | ||
158 | } | ||
159 | else // no redirect | ||
160 | { | ||
161 | // try the cache | ||
162 | texture = m_assetService.GetCached(fullID); | ||
163 | |||
164 | if (texture == null) | ||
165 | { | ||
166 | // m_log.DebugFormat("[GETTEXTURE]: texture was not in the cache"); | ||
167 | |||
168 | // Fetch locally or remotely. Misses return a 404 | ||
169 | texture = m_assetService.Get(textureID.ToString()); | ||
170 | |||
171 | if (texture != null) | ||
172 | { | 158 | { |
173 | if (texture.Type != (sbyte)AssetType.Texture) | 159 | AssetBase newTexture = new AssetBase(texture.ID + "-" + format, texture.Name, (sbyte)AssetType.Texture, texture.Metadata.CreatorID); |
174 | { | 160 | newTexture.Data = ConvertTextureData(texture, format); |
175 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | 161 | if (newTexture.Data.Length == 0) |
176 | return true; | 162 | return false; // !!! Caller try another codec, please! |
177 | } | 163 | |
178 | if (format == DefaultFormat) | 164 | newTexture.Flags = AssetFlags.Collectable; |
179 | { | 165 | newTexture.Temporary = true; |
180 | WriteTextureData(httpRequest, httpResponse, texture, format); | 166 | m_assetService.Store(newTexture); |
181 | return true; | 167 | WriteTextureData(request, response, newTexture, format); |
182 | } | 168 | return true; |
183 | else | ||
184 | { | ||
185 | AssetBase newTexture = new AssetBase(texture.ID + "-" + format, texture.Name, (sbyte)AssetType.Texture, texture.Metadata.CreatorID); | ||
186 | newTexture.Data = ConvertTextureData(texture, format); | ||
187 | if (newTexture.Data.Length == 0) | ||
188 | return false; // !!! Caller try another codec, please! | ||
189 | |||
190 | newTexture.Flags = AssetFlags.Collectable; | ||
191 | newTexture.Temporary = true; | ||
192 | m_assetService.Store(newTexture); | ||
193 | WriteTextureData(httpRequest, httpResponse, newTexture, format); | ||
194 | return true; | ||
195 | } | ||
196 | } | 169 | } |
197 | } | 170 | } |
198 | else // it was on the cache | 171 | } |
199 | { | 172 | else // it was on the cache |
200 | // m_log.DebugFormat("[GETTEXTURE]: texture was in the cache"); | 173 | { |
201 | WriteTextureData(httpRequest, httpResponse, texture, format); | 174 | //m_log.DebugFormat("[GETTEXTURE]: texture was in the cache"); |
202 | return true; | 175 | WriteTextureData(request, response, texture, format); |
203 | } | 176 | return true; |
204 | } | 177 | } |
205 | 178 | ||
206 | // not found | 179 | // not found |
207 | // m_log.Warn("[GETTEXTURE]: Texture " + textureID + " not found"); | 180 | // m_log.Warn("[GETTEXTURE]: Texture " + textureID + " not found"); |
208 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
209 | return true; | 181 | return true; |
210 | } | 182 | } |
211 | 183 | ||
212 | private void WriteTextureData(IOSHttpRequest request, IOSHttpResponse response, AssetBase texture, string format) | 184 | private void WriteTextureData(Hashtable request, Hashtable response, AssetBase texture, string format) |
213 | { | 185 | { |
214 | string range = request.Headers.GetOne("Range"); | 186 | Hashtable headers = new Hashtable(); |
187 | response["headers"] = headers; | ||
188 | |||
189 | string range = String.Empty; | ||
190 | |||
191 | if (((Hashtable)request["headers"])["range"] != null) | ||
192 | range = (string)((Hashtable)request["headers"])["range"]; | ||
193 | |||
194 | else if (((Hashtable)request["headers"])["Range"] != null) | ||
195 | range = (string)((Hashtable)request["headers"])["Range"]; | ||
215 | 196 | ||
216 | if (!String.IsNullOrEmpty(range)) // JP2's only | 197 | if (!String.IsNullOrEmpty(range)) // JP2's only |
217 | { | 198 | { |
@@ -239,10 +220,8 @@ namespace OpenSim.Capabilities.Handlers | |||
239 | // However, if we return PartialContent (or OK) instead, the viewer will display that resolution. | 220 | // However, if we return PartialContent (or OK) instead, the viewer will display that resolution. |
240 | 221 | ||
241 | // response.StatusCode = (int)System.Net.HttpStatusCode.RequestedRangeNotSatisfiable; | 222 | // response.StatusCode = (int)System.Net.HttpStatusCode.RequestedRangeNotSatisfiable; |
242 | // response.AddHeader("Content-Range", String.Format("bytes */{0}", texture.Data.Length)); | 223 | // viewers don't seem to handle RequestedRangeNotSatisfiable and keep retrying with same parameters |
243 | // response.StatusCode = (int)System.Net.HttpStatusCode.OK; | 224 | response["int_response_code"] = (int)System.Net.HttpStatusCode.NotFound; |
244 | response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent; | ||
245 | response.ContentType = texture.Metadata.ContentType; | ||
246 | } | 225 | } |
247 | else | 226 | else |
248 | { | 227 | { |
@@ -252,41 +231,46 @@ namespace OpenSim.Capabilities.Handlers | |||
252 | 231 | ||
253 | // m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID); | 232 | // m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID); |
254 | 233 | ||
255 | // Always return PartialContent, even if the range covered the entire data length | 234 | response["content-type"] = texture.Metadata.ContentType; |
256 | // We were accidentally sending back 404 before in this situation | 235 | |
257 | // https://issues.apache.org/bugzilla/show_bug.cgi?id=51878 supports sending 206 even if the | 236 | if (start == 0 && len == texture.Data.Length) // well redudante maybe |
258 | // entire range is requested, and viewer 3.2.2 (and very probably earlier) seems fine with this. | 237 | { |
259 | // | 238 | response["int_response_code"] = (int)System.Net.HttpStatusCode.OK; |
260 | // We also do not want to send back OK even if the whole range was satisfiable since this causes | 239 | response["bin_response_data"] = texture.Data; |
261 | // HTTP textures on at least Imprudence 1.4.0-beta2 to never display the final texture quality. | 240 | response["int_bytes"] = texture.Data.Length; |
262 | // if (end > maxEnd) | 241 | } |
263 | // response.StatusCode = (int)System.Net.HttpStatusCode.OK; | 242 | else |
264 | // else | 243 | { |
265 | response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent; | 244 | response["int_response_code"] = (int)System.Net.HttpStatusCode.PartialContent; |
266 | 245 | headers["Content-Range"] = String.Format("bytes {0}-{1}/{2}", start, end, texture.Data.Length); | |
267 | response.ContentLength = len; | 246 | |
268 | response.ContentType = texture.Metadata.ContentType; | 247 | byte[] d = new byte[len]; |
269 | response.AddHeader("Content-Range", String.Format("bytes {0}-{1}/{2}", start, end, texture.Data.Length)); | 248 | Array.Copy(texture.Data, start, d, 0, len); |
270 | 249 | response["bin_response_data"] = d; | |
271 | response.Body.Write(texture.Data, start, len); | 250 | response["int_bytes"] = len; |
251 | } | ||
252 | // response.Body.Write(texture.Data, start, len); | ||
272 | } | 253 | } |
273 | } | 254 | } |
274 | else | 255 | else |
275 | { | 256 | { |
276 | m_log.Warn("[GETTEXTURE]: Malformed Range header: " + range); | 257 | m_log.Warn("[GETTEXTURE]: Malformed Range header: " + range); |
277 | response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; | 258 | response["int_response_code"] = (int)System.Net.HttpStatusCode.BadRequest; |
278 | } | 259 | } |
279 | } | 260 | } |
280 | else // JP2's or other formats | 261 | else // JP2's or other formats |
281 | { | 262 | { |
282 | // Full content request | 263 | // Full content request |
283 | response.StatusCode = (int)System.Net.HttpStatusCode.OK; | 264 | response["int_response_code"] = (int)System.Net.HttpStatusCode.OK; |
284 | response.ContentLength = texture.Data.Length; | ||
285 | if (format == DefaultFormat) | 265 | if (format == DefaultFormat) |
286 | response.ContentType = texture.Metadata.ContentType; | 266 | response["content_type"] = texture.Metadata.ContentType; |
287 | else | 267 | else |
288 | response.ContentType = "image/" + format; | 268 | response["content_type"] = "image/" + format; |
289 | response.Body.Write(texture.Data, 0, texture.Data.Length); | 269 | |
270 | response["bin_response_data"] = texture.Data; | ||
271 | response["int_bytes"] = texture.Data.Length; | ||
272 | |||
273 | // response.Body.Write(texture.Data, 0, texture.Data.Length); | ||
290 | } | 274 | } |
291 | 275 | ||
292 | // if (response.StatusCode < 200 || response.StatusCode > 299) | 276 | // if (response.StatusCode < 200 || response.StatusCode > 299) |
@@ -390,4 +374,4 @@ namespace OpenSim.Capabilities.Handlers | |||
390 | return null; | 374 | return null; |
391 | } | 375 | } |
392 | } | 376 | } |
393 | } \ No newline at end of file | 377 | } |
diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs index 71cf033..bf66acb 100644 --- a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs +++ b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs | |||
@@ -33,6 +33,7 @@ using OpenSim.Framework.Servers.HttpServer; | |||
33 | using OpenSim.Server.Handlers.Base; | 33 | using OpenSim.Server.Handlers.Base; |
34 | using OpenMetaverse; | 34 | using OpenMetaverse; |
35 | 35 | ||
36 | /* | ||
36 | namespace OpenSim.Capabilities.Handlers | 37 | namespace OpenSim.Capabilities.Handlers |
37 | { | 38 | { |
38 | public class GetTextureServerConnector : ServiceConnector | 39 | public class GetTextureServerConnector : ServiceConnector |
@@ -63,7 +64,8 @@ namespace OpenSim.Capabilities.Handlers | |||
63 | throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); | 64 | throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); |
64 | 65 | ||
65 | server.AddStreamHandler( | 66 | server.AddStreamHandler( |
66 | new GetTextureHandler("/CAPS/GetTexture/" /*+ UUID.Random() */, m_AssetService, "GetTexture", null)); | 67 | new GetTextureHandler("/CAPS/GetTexture/", m_AssetService, "GetTexture", null)); |
67 | } | 68 | } |
68 | } | 69 | } |
69 | } \ No newline at end of file | 70 | } |
71 | */ | ||
diff --git a/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs b/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs index 761e4e7..b6ae41b 100644 --- a/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs +++ b/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs | |||
@@ -39,6 +39,7 @@ using OpenSim.Region.Framework.Scenes; | |||
39 | using OpenSim.Tests.Common; | 39 | using OpenSim.Tests.Common; |
40 | using OpenSim.Tests.Common.Mock; | 40 | using OpenSim.Tests.Common.Mock; |
41 | 41 | ||
42 | /* | ||
42 | namespace OpenSim.Capabilities.Handlers.GetTexture.Tests | 43 | namespace OpenSim.Capabilities.Handlers.GetTexture.Tests |
43 | { | 44 | { |
44 | [TestFixture] | 45 | [TestFixture] |
@@ -60,4 +61,5 @@ namespace OpenSim.Capabilities.Handlers.GetTexture.Tests | |||
60 | Assert.That(resp.StatusCode, Is.EqualTo((int)System.Net.HttpStatusCode.NotFound)); | 61 | Assert.That(resp.StatusCode, Is.EqualTo((int)System.Net.HttpStatusCode.NotFound)); |
61 | } | 62 | } |
62 | } | 63 | } |
63 | } \ No newline at end of file | 64 | } |
65 | */ | ||