aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs')
-rw-r--r--OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs28
1 files changed, 25 insertions, 3 deletions
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs
index ed3b4af..91c5c54 100644
--- a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs
+++ b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs
@@ -38,20 +38,31 @@ 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 protected override byte[] ProcessRequest(string path, Stream request, 68 protected override byte[] ProcessRequest(string path, Stream request,
@@ -64,9 +75,10 @@ namespace OpenSim.Server.Handlers.Asset
64 if (p.Length == 0) 75 if (p.Length == 0)
65 return result; 76 return result;
66 77
78 string id = string.Empty;
67 if (p.Length > 1) 79 if (p.Length > 1)
68 { 80 {
69 string id = p[0]; 81 id = p[0];
70 string cmd = p[1]; 82 string cmd = p[1];
71 83
72 if (cmd == "data") 84 if (cmd == "data")
@@ -117,7 +129,7 @@ namespace OpenSim.Server.Handlers.Asset
117 { 129 {
118 // Get the entire asset (metadata + data) 130 // Get the entire asset (metadata + data)
119 131
120 string id = p[0]; 132 id = p[0];
121 AssetBase asset = m_AssetService.Get(id); 133 AssetBase asset = m_AssetService.Get(id);
122 134
123 if (asset != null) 135 if (asset != null)
@@ -144,6 +156,16 @@ namespace OpenSim.Server.Handlers.Asset
144 result = new byte[0]; 156 result = new byte[0];
145 } 157 }
146 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 }
147 return result; 169 return result;
148 } 170 }
149 } 171 }