32 using System.Reflection;
35 using System.Text.RegularExpressions;
37 using System.Xml.Serialization;
38 using OpenSim.Server.Base;
39 using OpenSim.Services.Interfaces;
40 using OpenSim.Framework;
41 using OpenSim.Framework.ServiceAuth;
42 using OpenSim.Framework.Servers.HttpServer;
44 namespace OpenSim.Server.Handlers.
Asset
48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 private string m_RedirectURL;
54 base(
"GET",
"/assets")
56 m_AssetService = service;
60 base(
"GET",
"/assets", auth)
62 m_AssetService = service;
63 m_RedirectURL = redirectURL;
64 if (!m_RedirectURL.EndsWith(
"/"))
65 m_RedirectURL = m_RedirectURL.TrimEnd(
'/');
71 byte[] result =
new byte[0];
73 string[] p = SplitParams(path);
78 string id = string.Empty;
86 result = m_AssetService.GetData(id);
89 httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
95 httpResponse.StatusCode = (int)HttpStatusCode.OK;
96 httpResponse.
ContentType =
"application/octet-stream";
99 else if (cmd ==
"metadata")
103 if (metadata != null)
107 result = ServerUtils.SerializeResult(xs, metadata);
109 httpResponse.StatusCode = (int)HttpStatusCode.OK;
111 SLUtil.SLAssetTypeToContentType(metadata.
Type);
115 httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
117 result =
new byte[0];
123 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
125 result =
new byte[0];
128 else if (p.Length == 1)
133 AssetBase asset = m_AssetService.Get(id);
137 XmlSerializer xs =
new XmlSerializer(typeof(
AssetBase));
138 result = ServerUtils.SerializeResult(xs, asset);
140 httpResponse.StatusCode = (int)HttpStatusCode.OK;
142 SLUtil.SLAssetTypeToContentType(asset.
Type);
146 httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
148 result =
new byte[0];
154 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
156 result =
new byte[0];
159 if (httpResponse.
StatusCode == (
int)HttpStatusCode.NotFound && !string.IsNullOrEmpty(m_RedirectURL) && !
string.IsNullOrEmpty(
id))
161 httpResponse.StatusCode = (int)HttpStatusCode.Redirect;
162 string rurl = m_RedirectURL;
163 if (!path.StartsWith(
"/"))
166 httpResponse.AddHeader(
"Location", rurl);
167 m_log.DebugFormat(
"[ASSET GET HANDLER]: Asset not found, redirecting to {0} ({1})", rurl, httpResponse.StatusCode);
string ContentType
Content type property.
int StatusCode
HTTP status code.
Base streamed request handler.
AssetServerGetHandler(IAssetService service)
sbyte Type
(sbyte) AssetType enum
Asset class. All Assets are reference by this class or a class derived from this class ...
AssetServerGetHandler(IAssetService service, IServiceAuth auth, string redirectURL)
override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)