diff options
author | Justin Clark-Casey | 2014-05-27 23:29:54 +0100 |
---|---|---|
committer | Justin Clark-Casey | 2014-05-27 23:29:54 +0100 |
commit | 3f703ae1cb02cbcb0efaff061d495bacca941de0 (patch) | |
tree | 3221068b4bc4119023b3dfa621c19e126c2eb3f3 /OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs | |
parent | Merge branch 'master' into 0.8-post-fixes (diff) | |
parent | minor: Comment out 2 error level debugging message in authentication code (diff) | |
download | opensim-SC_OLD-3f703ae1cb02cbcb0efaff061d495bacca941de0.zip opensim-SC_OLD-3f703ae1cb02cbcb0efaff061d495bacca941de0.tar.gz opensim-SC_OLD-3f703ae1cb02cbcb0efaff061d495bacca941de0.tar.bz2 opensim-SC_OLD-3f703ae1cb02cbcb0efaff061d495bacca941de0.tar.xz |
Merge branch 'master' into 0.8-post-fixes
Diffstat (limited to 'OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs')
-rw-r--r-- | OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs | 28 |
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; | |||
38 | using OpenSim.Server.Base; | 38 | using OpenSim.Server.Base; |
39 | using OpenSim.Services.Interfaces; | 39 | using OpenSim.Services.Interfaces; |
40 | using OpenSim.Framework; | 40 | using OpenSim.Framework; |
41 | using OpenSim.Framework.ServiceAuth; | ||
41 | using OpenSim.Framework.Servers.HttpServer; | 42 | using OpenSim.Framework.Servers.HttpServer; |
42 | 43 | ||
43 | namespace OpenSim.Server.Handlers.Asset | 44 | namespace 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 | } |