diff options
Diffstat (limited to 'OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs')
-rw-r--r-- | OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs index 500ec50..91c5c54 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs | |||
@@ -48,6 +48,7 @@ namespace OpenSim.Server.Handlers.Asset | |||
48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
49 | 49 | ||
50 | private IAssetService m_AssetService; | 50 | private IAssetService m_AssetService; |
51 | private string m_RedirectURL; | ||
51 | 52 | ||
52 | public AssetServerGetHandler(IAssetService service) : | 53 | public AssetServerGetHandler(IAssetService service) : |
53 | base("GET", "/assets") | 54 | base("GET", "/assets") |
@@ -55,10 +56,13 @@ namespace OpenSim.Server.Handlers.Asset | |||
55 | m_AssetService = service; | 56 | m_AssetService = service; |
56 | } | 57 | } |
57 | 58 | ||
58 | public AssetServerGetHandler(IAssetService service, IServiceAuth auth) : | 59 | public AssetServerGetHandler(IAssetService service, IServiceAuth auth, string redirectURL) : |
59 | base("GET", "/assets", auth) | 60 | base("GET", "/assets", auth) |
60 | { | 61 | { |
61 | m_AssetService = service; | 62 | m_AssetService = service; |
63 | m_RedirectURL = redirectURL; | ||
64 | if (!m_RedirectURL.EndsWith("/")) | ||
65 | m_RedirectURL = m_RedirectURL.TrimEnd('/'); | ||
62 | } | 66 | } |
63 | 67 | ||
64 | protected override byte[] ProcessRequest(string path, Stream request, | 68 | protected override byte[] ProcessRequest(string path, Stream request, |
@@ -71,9 +75,10 @@ namespace OpenSim.Server.Handlers.Asset | |||
71 | if (p.Length == 0) | 75 | if (p.Length == 0) |
72 | return result; | 76 | return result; |
73 | 77 | ||
78 | string id = string.Empty; | ||
74 | if (p.Length > 1) | 79 | if (p.Length > 1) |
75 | { | 80 | { |
76 | string id = p[0]; | 81 | id = p[0]; |
77 | string cmd = p[1]; | 82 | string cmd = p[1]; |
78 | 83 | ||
79 | if (cmd == "data") | 84 | if (cmd == "data") |
@@ -124,7 +129,7 @@ namespace OpenSim.Server.Handlers.Asset | |||
124 | { | 129 | { |
125 | // Get the entire asset (metadata + data) | 130 | // Get the entire asset (metadata + data) |
126 | 131 | ||
127 | string id = p[0]; | 132 | id = p[0]; |
128 | AssetBase asset = m_AssetService.Get(id); | 133 | AssetBase asset = m_AssetService.Get(id); |
129 | 134 | ||
130 | if (asset != null) | 135 | if (asset != null) |
@@ -151,6 +156,16 @@ namespace OpenSim.Server.Handlers.Asset | |||
151 | result = new byte[0]; | 156 | result = new byte[0]; |
152 | } | 157 | } |
153 | 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 | } | ||
154 | return result; | 169 | return result; |
155 | } | 170 | } |
156 | } | 171 | } |