2008-03-31 Marek Habersack <mhabersack@novell.com>
authorMarek Habersack <grendel@twistedcode.net>
Mon, 31 Mar 2008 22:03:33 +0000 (22:03 -0000)
committerMarek Habersack <grendel@twistedcode.net>
Mon, 31 Mar 2008 22:03:33 +0000 (22:03 -0000)
* StaticFileHandler.cs: added code to use custom
VirtualPathProvider, if present, to serve files from virtual
storage.

* HttpResponse.cs: added two internal TransmitFile overloads which
take a VirtualFile as a parameter.

2008-04-01  Marek Habersack  <mhabersack@novell.com>

* HostingEnvironment.cs: initialize custom VPP on
registration.
Added an internal boolena property to signal if we're using a
custom VPP or not (HaveCustomVPP)

svn path=/trunk/mcs/; revision=99479

mcs/class/System.Web/System.Web.Hosting/ChangeLog
mcs/class/System.Web/System.Web.Hosting/HostingEnvironment.cs
mcs/class/System.Web/System.Web.Hosting/VirtualPathProvider.cs
mcs/class/System.Web/System.Web/ChangeLog
mcs/class/System.Web/System.Web/HttpResponse.cs
mcs/class/System.Web/System.Web/StaticFileHandler.cs

index 416cf05774c82860a3c1de8c323eaf3d85c2084b..4183707444a5a626e63e60ec0d69a92860f92998 100644 (file)
@@ -1,3 +1,15 @@
+2008-04-01  Marek Habersack  <mhabersack@novell.com>
+
+       * HostingEnvironment.cs: initialize custom VPP on
+       registration.
+       Added an internal boolena property to signal if we're using a
+       custom VPP or not (HaveCustomVPP)
+
+2008-03-31  Marek Habersack  <mhabersack@novell.com>
+
+       * VirtualPathProvider.cs: internal SetPrevious method renamed to
+       InitializeAndSetPrevious.
+
 2008-03-27  Marek Habersack  <mhabersack@novell.com>
 
        * DefaultVirtualPathProvider.cs: support relative virtual paths in
index 150ecb7772ce1df65ab8c6bcaac8915f2e3b430a..727b9c450864ff41d735774d6f51b4ccf42ff793 100644 (file)
@@ -53,6 +53,11 @@ namespace System.Web.Hosting {
                                                                new DefaultVirtualPathProvider ();
                static int busy_count;
 
+               internal static bool HaveCustomVPP {
+                       get;
+                       private set;
+               }
+               
                public HostingEnvironment ()
                {
                        // The documentation says that this is called once per domain by the ApplicationManager and
@@ -161,8 +166,13 @@ namespace System.Web.Hosting {
                        if (virtualPathProvider == null)
                                throw new ArgumentNullException ("virtualPathProvider");
 
-                       virtualPathProvider.SetPrevious (vpath_provider);
+                       VirtualPathProvider previous = vpath_provider;
                        vpath_provider = virtualPathProvider;
+                       vpath_provider.InitializeAndSetPrevious (previous);
+                       if (!(virtualPathProvider is DefaultVirtualPathProvider))
+                               HaveCustomVPP = true;
+                       else
+                               HaveCustomVPP = false;
                }
                
                public static IDisposable SetCultures (string virtualPath)
index 8e06450f3d45997df656e97f09b1fe16cafab7e0..9e829ca08df0edfbf3d0d1f139e112bafb7afdfb 100644 (file)
@@ -43,11 +43,6 @@ namespace System.Web.Hosting {
                {
                }
 
-               internal void SetPrevious (VirtualPathProvider prev)
-               {
-                       this.prev = prev;
-               }
-
                protected internal VirtualPathProvider Previous {
                        get { return prev; }
                }
@@ -56,6 +51,21 @@ namespace System.Web.Hosting {
                {
                }
 
+               internal void InitializeAndSetPrevious (VirtualPathProvider prev)
+               {
+                       Console.WriteLine ("{0}.InitializeAndSetPrevious ({1})", this, prev);
+                       this.prev = prev;
+                       Console.WriteLine ("\tprevious chain:");
+
+                       VirtualPathProvider p = this.prev;
+                       while (p != null) {
+                               Console.WriteLine ("\t\t{0}", p);
+                               p = p.Previous;
+                       }
+                       
+                       Initialize ();
+               }
+               
                public virtual string CombineVirtualPaths (string basePath, string relativePath)
                {
                        return VirtualPathUtility.Combine (basePath, relativePath);
index 5d96045849671a7485e226959888d80690cf9006..ec965b0a1650c0001d45b222f2889193ccb41dda 100644 (file)
@@ -1,3 +1,12 @@
+2008-03-31  Marek Habersack  <mhabersack@novell.com>
+
+       * StaticFileHandler.cs: added code to use custom
+       VirtualPathProvider, if present, to serve files from virtual
+       storage.
+
+       * HttpResponse.cs: added two internal TransmitFile overloads which
+       take a VirtualFile as a parameter.
+
 2008-03-27  Marek Habersack  <mhabersack@novell.com>
 
        * HttpRequest.cs: make UrlComponents internal.
index fc3c39807257c37293eccc9ed84786cac52fbda1..8720b459d7f775b1d9a94bb66c950a82806efa53 100644 (file)
@@ -39,6 +39,7 @@ using System.Web.Util;
 using System.Web.Configuration;
 using System.Globalization;
 using System.Security.Permissions;
+using System.Web.Hosting;
 
 namespace System.Web {
        
@@ -959,8 +960,29 @@ namespace System.Web {
                        output_stream.ApplyFilter (final_flush);
                        Flush (final_flush);
                }
-               
 
+#if NET_2_0
+               internal void TransmitFile (VirtualFile vf)
+               {
+                       TransmitFile (vf, false);
+               }
+               
+               internal void TransmitFile (VirtualFile vf, bool final_flush)
+               {
+                       if (vf == null)
+                               throw new ArgumentNullException ("vf");
+
+                       using (Stream s = vf.Open ()) {
+                               long len = s.Length;
+                               byte[] buf = new byte [len];
+                               int readBytes = s.Read (buf, 0, (int) len);
+                               output_stream.Write (buf, 0, readBytes);
+                               output_stream.ApplyFilter (final_flush);
+                               Flush (final_flush);
+                       }
+               }
+#endif
+               
 #region Session state support
                internal void SetAppPathModifier (string app_modifier)
                {
index 48827d096024b1b0337773e35d0c7d95433e9e70..2ed20085e1aa2fff055b2e66aa30ec42e04542c6 100644 (file)
@@ -32,6 +32,7 @@ using System;
 using System.Globalization;
 using System.IO;
 using System.Web.Util;
+using System.Web.Hosting;
 
 namespace System.Web
 {
@@ -60,6 +61,25 @@ namespace System.Web
                {
                        HttpRequest request = context.Request;
                        HttpResponse response = context.Response;
+
+#if NET_2_0
+                       if (HostingEnvironment.HaveCustomVPP) {
+                               VirtualFile vf = null;
+                               VirtualPathProvider vpp = HostingEnvironment.VirtualPathProvider;
+                               string vpath = request.FilePath;
+                               
+                               if (vpp.FileExists (vpath))
+                                       vf = vpp.GetFile (vpath);
+
+                               if (vf == null)
+                                       throw new HttpException (404, "Path '" + vpath + "' was not found.", vpath);
+
+                               response.ContentType = MimeTypes.GetMimeType (vpath);
+                               response.TransmitFile (vf);
+                               return;
+                       }
+#endif
+                       
                        string fileName = request.PhysicalPath;
                        FileInfo fi = new FileInfo (fileName);
                        if (!fi.Exists || !ValidFileName (fileName))
@@ -69,7 +89,7 @@ namespace System.Web
                                response.Redirect (request.Path + '/');
                                return;
                        }
-
+                       
                        string strHeader = request.Headers ["If-Modified-Since"];
                        try {
                                if (strHeader != null) {
@@ -103,7 +123,6 @@ namespace System.Web
                        try {
                                DateTime lastWT = fi.LastWriteTime.ToUniversalTime ();
                                response.AddHeader ("Last-Modified", lastWT.ToString ("r"));
-
                                response.ContentType = MimeTypes.GetMimeType (fileName);
                                response.TransmitFile (fileName, true);
                        } catch (Exception) {