From 27c8cc5b1fc78bad6a8286f4236e4ac094b32e52 Mon Sep 17 00:00:00 2001 From: Charles Krinke Date: Tue, 21 Apr 2009 19:42:36 +0000 Subject: Thank you kindly, TLaukkan for a patch that: Added support for loading bare asset binaries (as opposed to xml encoded asset base) to both sandbox asset service and cable beach. * Added support for enabling region asset service when mxp is enabled. * Moved base http server content type defaulting before invocation of request handle method to allow for variable content type in the response. --- OpenSim/Framework/Servers/BaseHttpServer.cs | 7 +- OpenSim/Framework/Servers/GetAssetStreamHandler.cs | 83 +++++++++++++++++----- 2 files changed, 72 insertions(+), 18 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Servers/BaseHttpServer.cs b/OpenSim/Framework/Servers/BaseHttpServer.cs index fc2d36a..121b8a8 100644 --- a/OpenSim/Framework/Servers/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/BaseHttpServer.cs @@ -303,6 +303,9 @@ namespace OpenSim.Framework.Servers //m_log.Debug("[BASE HTTP SERVER]: Found Stream Handler"); // Okay, so this is bad, but should be considered temporary until everything is IStreamHandler. byte[] buffer; + + response.ContentType = requestHandler.ContentType; // Lets do this defaulting before in case handler has varying content type. + if (requestHandler is IStreamedRequestHandler) { IStreamedRequestHandler streamedRequestHandler = requestHandler as IStreamedRequestHandler; @@ -371,7 +374,7 @@ namespace OpenSim.Framework.Servers } request.InputStream.Close(); - response.ContentType = requestHandler.ContentType; + if (!response.SendChunked) response.ContentLength64 = buffer.LongLength; @@ -1620,4 +1623,4 @@ namespace OpenSim.Framework.Servers return; } } -} \ No newline at end of file +} diff --git a/OpenSim/Framework/Servers/GetAssetStreamHandler.cs b/OpenSim/Framework/Servers/GetAssetStreamHandler.cs index d7fb72b..33b9e6e 100644 --- a/OpenSim/Framework/Servers/GetAssetStreamHandler.cs +++ b/OpenSim/Framework/Servers/GetAssetStreamHandler.cs @@ -38,6 +38,7 @@ using OpenSim.Data; using OpenSim.Framework; using OpenSim.Framework.Servers; using OpenSim.Framework.Statistics; +using System.Net; namespace OpenSim.Framework.Servers { @@ -90,20 +91,28 @@ namespace OpenSim.Framework.Servers // { // asset.Data = ProcessOutgoingAssetData(asset.Data); // } - - XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); - MemoryStream ms = new MemoryStream(); - XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8); - xw.Formatting = Formatting.Indented; - xs.Serialize(xw, asset); - xw.Flush(); - - ms.Seek(0, SeekOrigin.Begin); - //StreamReader sr = new StreamReader(ms); - - result = ms.GetBuffer(); - - Array.Resize(ref result, (int)ms.Length); + if (p.Length > 1 && p[1] == "data") + { + httpResponse.StatusCode = (int)HttpStatusCode.OK; + httpResponse.ContentType = SLAssetTypeToContentType(asset.Type); + result = asset.Data; + } + else + { + XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); + MemoryStream ms = new MemoryStream(); + XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8); + xw.Formatting = Formatting.Indented; + xs.Serialize(xw, asset); + xw.Flush(); + + ms.Seek(0, SeekOrigin.Begin); + //StreamReader sr = new StreamReader(ms); + + result = ms.GetBuffer(); + + Array.Resize(ref result, (int)ms.Length); + } } else { @@ -160,6 +169,48 @@ namespace OpenSim.Framework.Servers return data; } - + + private string SLAssetTypeToContentType(int assetType) + { + switch (assetType) + { + case 0: + return "image/jp2"; + case 1: + return "application/ogg"; + case 2: + return "application/x-metaverse-callingcard"; + case 3: + return "application/x-metaverse-landmark"; + case 5: + return "application/x-metaverse-clothing"; + case 6: + return "application/x-metaverse-primitive"; + case 7: + return "application/x-metaverse-notecard"; + case 8: + return "application/x-metaverse-folder"; + case 10: + return "application/x-metaverse-lsl"; + case 11: + return "application/x-metaverse-lso"; + case 12: + return "image/tga"; + case 13: + return "application/x-metaverse-bodypart"; + case 17: + return "audio/x-wav"; + case 19: + return "image/jpeg"; + case 20: + return "application/x-metaverse-animation"; + case 21: + return "application/x-metaverse-gesture"; + case 22: + return "application/x-metaverse-simstate"; + default: + return "application/octet-stream"; + } + } } -} \ No newline at end of file +} -- cgit v1.1