fwd: Re: [Mono-devel-list] SimpleWorkerRequest patch for PATH_INFO

eric lindvall eric at 5stops.com
Sat Jun 14 02:12:08 EDT 2003


meant to send this to the list as well.

e.


----- Forwarded message from eric lindvall <eric at 5stops.com> -----

Date: Thu, 12 Jun 2003 12:54:04 -0700
From: eric lindvall <eric at 5stops.com>
To: Gonzalo Paniagua Javier <gonzalo at ximian.com>
Subject: Re: [Mono-devel-list] SimpleWorkerRequest patch for PATH_INFO
X-PGPv5-Key-Id: 0xDB458469

one more try.. sorry for not doing more testing before i submitted the
first (or second) one.

what this does:
 - adds PATH_INFO support
 - updates GetFilePathTranslated() to make use of Path.Combine()
 - gets rid of the null check in GetPathInfo() (we're setting _PathInfo to 
   String.Empty now)
 - fixed CreatePath() so that it doesn't return String.Empty if the 
   _AppVirtualPath is not "/" (to match MS runtime -- does anyone know why it 
   was returning String.Empty?)

e.


On Thu, 12 Jun 2003, Gonzalo Paniagua Javier wrote:

> El jue, 12-06-2003 a las 08:18, eric lindvall escribió:
> > Here's a little patch that cleans up SimpleWorkerRequest a little bit
> > (trying to match the MS implementation a little more) and adding PATH_INFO
> > parsing.
> 
> It makes xsp server throw this exception when i try to get
> http://127.0.0.1:8080/ :
> 
> Unhandled Exception: System.NullReferenceException: A null value was
> found where an object instance was required
> in [0x00039] (at
> /home/gpanjav/go-mono/xsp/server/MonoWorkerRequest.cs:209) 00
> Mono.ASPNET.MonoWorkerRequest:MapPath (string)
> in [0x00013] (at
> /home/gpanjav/go-mono/xsp/server/MonoWorkerRequest.cs:142) 00
> Mono.ASPNET.MonoWorkerRequest:GetFilePathTranslated ()
> in <0x00035> 00 System.Web.Hosting.SimpleWorkerRequest:ParsePathInfo ()
> in <0x001c2> 00 System.Web.Hosting.SimpleWorkerRequest:.ctor
> (string,string,System.IO.TextWriter)
> in [0x0000c] (at
> /home/gpanjav/go-mono/xsp/server/MonoWorkerRequest.cs:107) 00
> Mono.ASPNET.MonoWorkerRequest:.ctor (Mono.ASPNET.IApplicationHost)
> in [0x00002] (at
> /home/gpanjav/go-mono/xsp/server/XSPWorkerRequest.cs:95) 00
> Mono.ASPNET.XSPWorkerRequest:.ctor
> (System.Net.Sockets.Socket,Mono.ASPNET.IApplicationHost)
> in [0x0000c] (at
> /home/gpanjav/go-mono/xsp/server/XSPApplicationHost.cs:34) 00
> Mono.ASPNET.Worker:Run (object)
> 
> -Gonzalo
> 
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list

Index: SimpleWorkerRequest.cs
===================================================================
RCS file: /mono/mcs/class/System.Web/System.Web.Hosting/SimpleWorkerRequest.cs,v
retrieving revision 1.6
diff -u -p -u -r1.6 SimpleWorkerRequest.cs
--- SimpleWorkerRequest.cs	4 Feb 2003 17:05:45 -0000	1.6
+++ SimpleWorkerRequest.cs	12 Jun 2003 19:48:35 -0000
@@ -17,7 +17,7 @@ namespace System.Web.Hosting
 	{
 		private string _Page;
 		private string _Query;
-		private string _PathInfo;
+		private string _PathInfo = String.Empty;
 		private string _AppVirtualPath;
 		private string _AppPhysicalPath;
 		private string _AppInstallPath;
@@ -31,7 +31,6 @@ namespace System.Web.Hosting
 		public SimpleWorkerRequest (string Page, string Query, TextWriter Output)
 		{
 			_Page = Page;
-			ParsePathInfo ();
 
 			_Query = Query;
 			AppDomain current = AppDomain.CurrentDomain;
@@ -55,6 +54,8 @@ namespace System.Web.Hosting
 				throw new HttpException ("Invalid app domain");
 
 			_HasInstallInfo = true;
+
+			ExtractPagePathInfo();
 		}
 
 		public SimpleWorkerRequest (string AppVirtualPath,
@@ -67,12 +68,13 @@ namespace System.Web.Hosting
 				throw new HttpException ("Invalid app domain");
 
 			_Page = Page;
-			ParsePathInfo ();
 			_Query = Query;
 			_AppVirtualPath = AppVirtualPath;
 			_AppPhysicalPath = CheckAndAddSlash (AppPhysicalPath);
 			_Output = Output;
 			_HasInstallInfo = false;
+
+			ExtractPagePathInfo();
 		}
 
 		[MonoTODO("Implement security")]
@@ -119,10 +121,14 @@ namespace System.Web.Hosting
 
 		public override string GetFilePathTranslated ()
 		{
+                        string page = _Page;
+
 			if (Path.DirectorySeparatorChar != '/')
-				return _AppPhysicalPath + _Page.Replace ('/', Path.DirectorySeparatorChar);
+                        {
+                                page = _Page.Replace ('/', Path.DirectorySeparatorChar);
+                        }
 
-			return _AppPhysicalPath + _Page;
+			return (Path.Combine (_AppPhysicalPath, page));
 		}
 
 		public override string GetHttpVerbName ()
@@ -147,7 +153,7 @@ namespace System.Web.Hosting
 
 		public override string GetPathInfo ()
 		{
-			return (null != _PathInfo) ? _PathInfo : String.Empty;
+			return _PathInfo;
 		}
 
 		public override string GetQueryString ()
@@ -258,27 +264,45 @@ namespace System.Web.Hosting
 		// Create's a path string
 		private string CreatePath (bool bIncludePathInfo)
 		{
-			string sPath;
+			string sPath = Path.Combine (_AppVirtualPath, _Page);
 
-			if ("/" != _AppVirtualPath)
-				sPath = "/" + _Page;
-			else
-				sPath = String.Empty;
-
-			if (bIncludePathInfo && null != _PathInfo)
-				return sPath + _PathInfo;
+			if (bIncludePathInfo)
+                        {
+                                sPath += _PathInfo;
+                        }
 
 			return sPath;
 		}
 
 		// Parses out the string after / known as the "path info"
-		private void ParsePathInfo ()
+		private void ExtractPagePathInfo ()
 		{
-		/*	int iPos = _Page.LastIndexOf("/");
-			if (iPos >= 0) {
-				_PathInfo = _Page.Substring (iPos);
-				_Page = _Page.Substring (0, iPos);
-			}*/
+                        if (_Page == null || _Page == String.Empty)
+                        {
+                            return;
+                        }
+
+                        string FullPath = GetFilePathTranslated();
+
+                        StringBuilder PathInfo = new StringBuilder();
+
+                        int MinLen = FullPath.Length - _Page.Length;
+
+                        while (!(Directory.Exists (FullPath) || File.Exists (FullPath)))
+                        {
+                            int last = FullPath.LastIndexOf (Path.DirectorySeparatorChar);
+
+                            if (last == -1 || last < MinLen)
+                            {
+                                return;
+                            }
+
+                            PathInfo.Insert (0, FullPath.Substring (last));
+                            FullPath = FullPath.Substring (0, last);
+                        }
+
+                        _Page = _Page.Substring (0, _Page.Length - PathInfo.Length);
+                        _PathInfo = PathInfo.ToString();
 		}
 	}
 }


----- End forwarded message -----



More information about the Mono-devel-list mailing list