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

eric lindvall eric at 5stops.com
Wed Jun 25 01:51:33 EDT 2003


this should fix the problems with the previous patch.

i checked how the MS .NET framework dealt with the PATH_INFO, and the
things i noticed were:

- if it finds a file that exists, everything after that is the PATH_INFO
- if it finds a directory that exists, the entry before it is considered
  the "file", and everything after that is the PATH_INFO


http://localhost:8080/one/two/index.aspx/happy/days

so if "/one/two/index.aspx" exists, "/one/two/index.aspx" is the _Page, "/happy/days" is the PATH_INFO.

if "/one" exists, "/one/two" is the _Page, "/index.aspx/happy/days" is the
PATH_INFO.

e.


On Sat, 14 Jun 2003, Ben Maurer wrote:

> On Sat, 2003-06-14 at 02:12, eric lindvall wrote:
> > 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?)
> 
> Eric,
> 
> Thank you for this patch, this may end up saving my rear ;-). It does do
> a few things wrong however.
> 
> If you request http://localhost:8080/dir/path_info, you will get a 404
> (tested with Cassini, IIS). If you request
> http://localhost:8080/trace.axd/pathinfo, where trace.axd is handled by
> a handler (as it is with MS's impl), you do get a page.
> 
> We need to figure out the way MS does this.
> 
> Also, can you please make sure that this is implemented in System.Web
> under MS? I think I tested this before and it was not. 
> 
> -- Ben
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
-------------- next part --------------
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	25 Jun 2003 05:42:15 -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")]
@@ -114,15 +116,19 @@ namespace System.Web.Hosting
 
 		public override string GetFilePath ()
 		{
-			return CreatePath (false);
+                        return CreatePath (false);
 		}
 
 		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 ()
@@ -157,8 +163,8 @@ namespace System.Web.Hosting
 
 		public override string GetRawUrl ()
 		{
-			string path = CreatePath (true);
-			if (null != _Query && _Query.Length > 0)
+                        string path = CreatePath (true);
+                        if (null != _Query && _Query.Length > 0)
 				return path + "?" + _Query;
 
 			return path;
@@ -256,30 +262,68 @@ namespace System.Web.Hosting
 		}
 
 		// Create's a path string
-		private string CreatePath (bool bIncludePathInfo)
-		{
-			string sPath;
-
-			if ("/" != _AppVirtualPath)
-				sPath = "/" + _Page;
-			else
-				sPath = String.Empty;
-
-			if (bIncludePathInfo && null != _PathInfo)
-				return sPath + _PathInfo;
-
-			return sPath;
-		}
-
-		// Parses out the string after / known as the "path info"
-		private void ParsePathInfo ()
-		{
-		/*	int iPos = _Page.LastIndexOf("/");
-			if (iPos >= 0) {
-				_PathInfo = _Page.Substring (iPos);
-				_Page = _Page.Substring (0, iPos);
-			}*/
-		}
+                private string CreatePath (bool bIncludePathInfo)
+                {
+                        string sPath = Path.Combine (_AppVirtualPath, _Page);
+
+                        if (bIncludePathInfo)
+                        {
+                                sPath += _PathInfo;
+                        }
+
+                        return sPath;
+		}
+
+                //  "The extra path information, as given by the client. In
+                //  other words, scripts can be accessed by their virtual
+                //  pathname, followed by extra information at the end of this
+                //  path. The extra information is sent as PATH_INFO."
+                private void ExtractPagePathInfo ()
+                {
+                        if (_Page == null || _Page == String.Empty)
+                        {
+                                return;
+                        }
+
+                        string FullPath = GetFilePathTranslated();
+
+                        int PathInfoLength = 0;
+
+                        string LastFile = String.Empty;
+
+                        while (PathInfoLength < _Page.Length)
+                        {
+                                if (LastFile.Length > 0)
+                                {
+                                        // increase it by the length of the file plus 
+                                        // a "/"
+                                        //
+                                        PathInfoLength += LastFile.Length + 1;
+                                }
+
+                                if (File.Exists (FullPath) == true)
+                                {
+                                        break;
+                                }
+
+                                if (Directory.Exists (FullPath) == true)
+                                {
+                                        PathInfoLength -= (LastFile.Length + 1);
+                                        break;
+                                }
+
+                                LastFile = Path.GetFileName (FullPath);
+                                FullPath = Path.GetDirectoryName (FullPath);
+                        }
+
+                        if (PathInfoLength > _Page.Length)
+                        {
+                                return;
+                        }
+
+                        _PathInfo = _Page.Substring (_Page.Length - PathInfoLength);
+                        _Page = _Page.Substring (0, _Page.Length - PathInfoLength);
+                }
 	}
 }
 


More information about the Mono-devel-list mailing list