2 // System.Web.Handlers.AssemblyResourceLoader
5 // Ben Maurer (bmaurer@users.sourceforge.net)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Reflection;
36 namespace System.Web.Handlers {
37 [MonoTODO ("Should we cache stuff?")]
41 internal // since this is in the .config file, we need to support it, since we dont have versoned support.
43 class AssemblyResourceLoader : IHttpHandler {
45 internal static string GetResourceUrl (Type type, string resourceName)
47 string aname = type.Assembly == typeof(AssemblyResourceLoader).Assembly ? "s" : HttpUtility.UrlEncode (type.Assembly.GetName ().FullName);
48 return "WebResource.axd?a="
51 + HttpUtility.UrlEncode (resourceName);
55 [MonoTODO ("Substitution not implemented")]
56 void System.Web.IHttpHandler.ProcessRequest (HttpContext context)
59 string resourceName = context.Request.QueryString ["r"];
60 string asmName = context.Request.QueryString ["a"];
63 if (asmName == null || asmName == "s") assembly = GetType().Assembly;
64 else assembly = Assembly.Load (asmName);
67 foreach (WebResourceAttribute wra in assembly.GetCustomAttributes (typeof (WebResourceAttribute), false)) {
68 if (wra.WebResource == resourceName) {
69 context.Response.ContentType = wra.ContentType;
71 if (wra.PerformSubstitution)
72 throw new NotImplementedException ("Substitution not implemented");
81 Stream s = assembly.GetManifestResourceStream (resourceName);
83 byte [] buf = new byte [1024];
84 Stream output = context.Response.OutputStream;
87 c = s.Read (buf, 0, 1024);
88 output.Write (buf, 0, c);
93 bool System.Web.IHttpHandler.IsReusable { get { return true; } }