Selaa lähdekoodia

2008-03-31 Marek Habersack <[email protected]>

	* 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  <[email protected]>

	* 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
Marek Habersack 18 vuotta sitten
vanhempi
sitoutus
42434ae85f

+ 12 - 0
mcs/class/System.Web/System.Web.Hosting/ChangeLog

@@ -1,3 +1,15 @@
+2008-04-01  Marek Habersack  <[email protected]>
+
+	* 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  <[email protected]>
+
+	* VirtualPathProvider.cs: internal SetPrevious method renamed to
+	InitializeAndSetPrevious.
+
 2008-03-27  Marek Habersack  <[email protected]>
 
 	* DefaultVirtualPathProvider.cs: support relative virtual paths in

+ 11 - 1
mcs/class/System.Web/System.Web.Hosting/HostingEnvironment.cs

@@ -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)

+ 15 - 5
mcs/class/System.Web/System.Web.Hosting/VirtualPathProvider.cs

@@ -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);

+ 9 - 0
mcs/class/System.Web/System.Web/ChangeLog

@@ -1,3 +1,12 @@
+2008-03-31  Marek Habersack  <[email protected]>
+
+	* 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  <[email protected]>
 
 	* HttpRequest.cs: make UrlComponents internal.

+ 23 - 1
mcs/class/System.Web/System.Web/HttpResponse.cs

@@ -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)
 		{

+ 21 - 2
mcs/class/System.Web/System.Web/StaticFileHandler.cs

@@ -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) {