[Mono-devel-list] SimpleWorkerRequest patch for PATH_INFO
eric lindvall
eric at 5stops.com
Thu Jun 12 02:18:25 EDT 2003
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.
e.
-------------- 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 12 Jun 2003 06:16:15 -0000
@@ -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;
+
+ ParsePathInfo ();
}
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;
+
+ ParsePathInfo ();
}
[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 ()
@@ -258,15 +264,12 @@ namespace System.Web.Hosting
// Create's a path string
private string CreatePath (bool bIncludePathInfo)
{
- string sPath;
-
- if ("/" != _AppVirtualPath)
- sPath = "/" + _Page;
- else
- sPath = String.Empty;
+ string sPath = Path.Combine (_AppVirtualPath, _Page);
if (bIncludePathInfo && null != _PathInfo)
- return sPath + _PathInfo;
+ {
+ sPath = Path.Combine (sPath, _PathInfo);
+ }
return sPath;
}
@@ -274,11 +277,25 @@ namespace System.Web.Hosting
// 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);
- }*/
+ if (_Page == null)
+ {
+ return;
+ }
+
+ string FullPath = GetFilePathTranslated();
+
+ StringBuilder PathInfo = new StringBuilder();
+
+ while (!(Directory.Exists (FullPath) || File.Exists (FullPath)))
+ {
+ int last = FullPath.LastIndexOf (Path.DirectorySeparatorChar);
+
+ PathInfo.Insert (0, FullPath.Substring (last));
+ FullPath = FullPath.Substring (0, last);
+ }
+
+ _Page = _Page.Substring (0, _Page.Length - PathInfo.Length);
+ _PathInfo = PathInfo.ToString();
}
}
}
More information about the Mono-devel-list
mailing list