aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs
diff options
context:
space:
mode:
authorDavid Walter Seikel2016-11-03 21:44:39 +1000
committerDavid Walter Seikel2016-11-03 21:44:39 +1000
commit134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch)
tree216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs
parentMore changing to production grid. Double oops. (diff)
downloadopensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to '')
-rw-r--r--OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs100
1 files changed, 73 insertions, 27 deletions
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs
index 8f7412b..91c5c54 100644
--- a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs
+++ b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs
@@ -38,23 +38,34 @@ using System.Xml.Serialization;
38using OpenSim.Server.Base; 38using OpenSim.Server.Base;
39using OpenSim.Services.Interfaces; 39using OpenSim.Services.Interfaces;
40using OpenSim.Framework; 40using OpenSim.Framework;
41using OpenSim.Framework.ServiceAuth;
41using OpenSim.Framework.Servers.HttpServer; 42using OpenSim.Framework.Servers.HttpServer;
42 43
43namespace OpenSim.Server.Handlers.Asset 44namespace OpenSim.Server.Handlers.Asset
44{ 45{
45 public class AssetServerGetHandler : BaseStreamHandler 46 public class AssetServerGetHandler : BaseStreamHandler
46 { 47 {
47 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 49
49 private IAssetService m_AssetService; 50 private IAssetService m_AssetService;
51 private string m_RedirectURL;
50 52
51 public AssetServerGetHandler(IAssetService service) : 53 public AssetServerGetHandler(IAssetService service) :
52 base("GET", "/assets") 54 base("GET", "/assets")
53 { 55 {
56 m_AssetService = service;
57 }
58
59 public AssetServerGetHandler(IAssetService service, IServiceAuth auth, string redirectURL) :
60 base("GET", "/assets", auth)
61 {
54 m_AssetService = service; 62 m_AssetService = service;
63 m_RedirectURL = redirectURL;
64 if (!m_RedirectURL.EndsWith("/"))
65 m_RedirectURL = m_RedirectURL.TrimEnd('/');
55 } 66 }
56 67
57 public override byte[] Handle(string path, Stream request, 68 protected override byte[] ProcessRequest(string path, Stream request,
58 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 69 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
59 { 70 {
60 byte[] result = new byte[0]; 71 byte[] result = new byte[0];
@@ -64,45 +75,62 @@ namespace OpenSim.Server.Handlers.Asset
64 if (p.Length == 0) 75 if (p.Length == 0)
65 return result; 76 return result;
66 77
67 if (p.Length > 1 && p[1] == "data") 78 string id = string.Empty;
79 if (p.Length > 1)
68 { 80 {
69 result = m_AssetService.GetData(p[0]); 81 id = p[0];
70 if (result == null) 82 string cmd = p[1];
83
84 if (cmd == "data")
71 { 85 {
72 httpResponse.StatusCode = (int)HttpStatusCode.NotFound; 86 result = m_AssetService.GetData(id);
73 httpResponse.ContentType = "text/plain"; 87 if (result == null)
74 result = new byte[0]; 88 {
89 httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
90 httpResponse.ContentType = "text/plain";
91 result = new byte[0];
92 }
93 else
94 {
95 httpResponse.StatusCode = (int)HttpStatusCode.OK;
96 httpResponse.ContentType = "application/octet-stream";
97 }
75 } 98 }
76 else 99 else if (cmd == "metadata")
77 { 100 {
78 httpResponse.StatusCode = (int)HttpStatusCode.OK; 101 AssetMetadata metadata = m_AssetService.GetMetadata(id);
79 httpResponse.ContentType = "application/octet-stream";
80 }
81 }
82 else if (p.Length > 1 && p[1] == "metadata")
83 {
84 AssetMetadata metadata = m_AssetService.GetMetadata(p[0]);
85 102
86 if (metadata != null) 103 if (metadata != null)
87 { 104 {
88 XmlSerializer xs = 105 XmlSerializer xs =
89 new XmlSerializer(typeof(AssetMetadata)); 106 new XmlSerializer(typeof(AssetMetadata));
90 result = ServerUtils.SerializeResult(xs, metadata); 107 result = ServerUtils.SerializeResult(xs, metadata);
91 108
92 httpResponse.StatusCode = (int)HttpStatusCode.OK; 109 httpResponse.StatusCode = (int)HttpStatusCode.OK;
93 httpResponse.ContentType = 110 httpResponse.ContentType =
94 SLUtil.SLAssetTypeToContentType(metadata.Type); 111 SLUtil.SLAssetTypeToContentType(metadata.Type);
112 }
113 else
114 {
115 httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
116 httpResponse.ContentType = "text/plain";
117 result = new byte[0];
118 }
95 } 119 }
96 else 120 else
97 { 121 {
98 httpResponse.StatusCode = (int)HttpStatusCode.NotFound; 122 // Unknown request
123 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
99 httpResponse.ContentType = "text/plain"; 124 httpResponse.ContentType = "text/plain";
100 result = new byte[0]; 125 result = new byte[0];
101 } 126 }
102 } 127 }
103 else 128 else if (p.Length == 1)
104 { 129 {
105 AssetBase asset = m_AssetService.Get(p[0]); 130 // Get the entire asset (metadata + data)
131
132 id = p[0];
133 AssetBase asset = m_AssetService.Get(id);
106 134
107 if (asset != null) 135 if (asset != null)
108 { 136 {
@@ -120,6 +148,24 @@ namespace OpenSim.Server.Handlers.Asset
120 result = new byte[0]; 148 result = new byte[0];
121 } 149 }
122 } 150 }
151 else
152 {
153 // Unknown request
154 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
155 httpResponse.ContentType = "text/plain";
156 result = new byte[0];
157 }
158
159 if (httpResponse.StatusCode == (int)HttpStatusCode.NotFound && !string.IsNullOrEmpty(m_RedirectURL) && !string.IsNullOrEmpty(id))
160 {
161 httpResponse.StatusCode = (int)HttpStatusCode.Redirect;
162 string rurl = m_RedirectURL;
163 if (!path.StartsWith("/"))
164 rurl += "/";
165 rurl += path;
166 httpResponse.AddHeader("Location", rurl);
167 m_log.DebugFormat("[ASSET GET HANDLER]: Asset not found, redirecting to {0} ({1})", rurl, httpResponse.StatusCode);
168 }
123 return result; 169 return result;
124 } 170 }
125 } 171 }