/// <summary> /// Parses the parameters and tries to deduce consistent /// values for the following from other parameters that /// may be supplied by the web server: /// SCRIPT_NAME (virtual path), /// SCRIPT_FILENAME (physical path), /// PATH_INFO (virtual path-info) and /// PATH_TRANSLATED (physical path-info). /// Required by Apache. /// </summary> void ParseParameterData() { string redirectUrl; string pathInfo = GetParameter ("PATH_INFO"); string pathTranslated = GetParameter ("PATH_TRANSLATED"); Mono.WebServer.VPathToHost vapp; if (pathTranslated == null || pathTranslated.Length == 0 || pathInfo == null || pathInfo.Length == 0 || pathInfo [0] != '/' || (null != (redirectUrl = GetParameter ("REDIRECT_URL")) && redirectUrl.Length != 0 && pathInfo != redirectUrl)) { // Only consider REDIRECT_URL if it actually contains // something, since it may not always be present (depending // on installed Apache modules & setup). Also, never allow // PATH_INFO to be null (nor PATH_TRANSLATED), even for // cases where this method is mostly short-circuited. if (pathInfo == null) SetParameter ("PATH_INFO", String.Empty); if (pathTranslated == null) SetParameter ("PATH_TRANSLATED", String.Empty); vapp = Mono.WebServer.FastCgi.Server.GetApplicationForPath (this.HostName, this.PortNumber, this.Path, this.PhysicalPath); if (vapp != null) appHost = (Mono.WebServer.FastCgi.ApplicationHost)vapp.AppHost; return; } // At this point we have: (with REDIRECT_URL being optional) // // REDIRECT_URL=/dir/test.aspx/foo // PATH_INFO=/dir/test.aspx/foo // PATH_TRANSLATED=/srv/www/htdocs/dir/test.aspx/foo // SCRIPT_NAME=/cgi-bin/fastcgi-mono-server // SCRIPT_FILENAME=/srv/www/cgi-bin/fastcgi-mono-server string virtPath = pathInfo; string physPath = pathTranslated; string virtPathInfo = String.Empty; string physPathInfo = String.Empty; try { vapp = Mono.WebServer.FastCgi.Server.GetApplicationForPath ( this.HostName, this.PortNumber, virtPath, physPath); if (vapp == null) return; // Set values in finally appHost = (Mono.WebServer.FastCgi.ApplicationHost)vapp.AppHost; if (appHost == null) return; // Set values in finally // Split the virtual path and virtual path-info string verb = GetParameter ("REQUEST_METHOD"); if (verb == null || verb.Length == 0) verb = "GET"; // For the sake of paths, assume a default appHost.GetPathsFromUri (verb, pathInfo, out virtPath, out virtPathInfo); if (virtPathInfo == null) virtPathInfo = String.Empty; if (virtPath == null) virtPath = String.Empty; // Re-map the physical path physPath = appHost.MapPath (virtPath); if (physPath == null) physPath = String.Empty; // Re-map the physical path-info string relaPathInfo = virtPathInfo; if (relaPathInfo.Length != 0 && IOPath.DirectorySeparatorChar != '/') relaPathInfo = relaPathInfo.Replace ('/', IOPath.DirectorySeparatorChar); while (relaPathInfo.Length > 0 && relaPathInfo[0] == IOPath.DirectorySeparatorChar) { relaPathInfo = relaPathInfo.Substring (1); } if (physPath.Length == 0) { physPathInfo = relaPathInfo; return; // Set values in finally } string physRoot = physPath; try { if (appHost.VirtualFileExists (virtPath)) { physRoot = IOPath.GetDirectoryName (physRoot); if (physRoot == null) physRoot = String.Empty; } } catch { // Assume virtPath, physPath & physRoot // specify directories (and not files) } physPathInfo = IOPath.Combine (physRoot, relaPathInfo); } finally { // Now, if all went well, we set: // // SCRIPT_NAME=/dir/test.aspx // SCRIPT_FILENAME=/srv/www/htdocs/dir/test.aspx // PATH_INFO=/foo // PATH_TRANSLATED=/srv/www/htdocs/dir/foo SetParameter ("SCRIPT_NAME", virtPath); SetParameter ("SCRIPT_FILENAME", physPath); SetParameter ("PATH_INFO", virtPathInfo); SetParameter ("PATH_TRANSLATED", physPathInfo); } }
void ParseParameterData() { string redirectUrl; string pathInfo = GetParameter("PATH_INFO"); string pathTranslated = GetParameter("PATH_TRANSLATED"); Mono.WebServer.VPathToHost vapp; if (pathTranslated == null || pathTranslated.Length == 0 || pathInfo == null || pathInfo.Length == 0 || pathInfo [0] != '/' || (null != (redirectUrl = GetParameter("REDIRECT_URL")) && redirectUrl.Length != 0 && pathInfo != redirectUrl)) { // Only consider REDIRECT_URL if it actually contains // something, since it may not always be present (depending // on installed Apache modules & setup). Also, never allow // PATH_INFO to be null (nor PATH_TRANSLATED), even for // cases where this method is mostly short-circuited. if (pathInfo == null) { SetParameter("PATH_INFO", String.Empty); } if (pathTranslated == null) { SetParameter("PATH_TRANSLATED", String.Empty); } vapp = Mono.WebServer.FastCgi.Server.GetApplicationForPath(this.HostName, this.PortNumber, this.Path, this.PhysicalPath); if (vapp != null) { appHost = (Mono.WebServer.FastCgi.ApplicationHost)vapp.AppHost; } return; } // At this point we have: (with REDIRECT_URL being optional) // // REDIRECT_URL=/dir/test.aspx/foo // PATH_INFO=/dir/test.aspx/foo // PATH_TRANSLATED=/srv/www/htdocs/dir/test.aspx/foo // SCRIPT_NAME=/cgi-bin/fastcgi-mono-server // SCRIPT_FILENAME=/srv/www/cgi-bin/fastcgi-mono-server string virtPath = pathInfo; string physPath = pathTranslated; string virtPathInfo = String.Empty; string physPathInfo = String.Empty; try { vapp = Mono.WebServer.FastCgi.Server.GetApplicationForPath( this.HostName, this.PortNumber, virtPath, physPath); if (vapp == null) { return; // Set values in finally } appHost = (Mono.WebServer.FastCgi.ApplicationHost)vapp.AppHost; if (appHost == null) { return; // Set values in finally } // Split the virtual path and virtual path-info string verb = GetParameter("REQUEST_METHOD"); if (verb == null || verb.Length == 0) { verb = "GET"; // For the sake of paths, assume a default } appHost.GetPathsFromUri(verb, pathInfo, out virtPath, out virtPathInfo); if (virtPathInfo == null) { virtPathInfo = String.Empty; } if (virtPath == null) { virtPath = String.Empty; } // Re-map the physical path physPath = appHost.MapPath(virtPath); if (physPath == null) { physPath = String.Empty; } // Re-map the physical path-info string relaPathInfo = virtPathInfo; if (relaPathInfo.Length != 0 && IOPath.DirectorySeparatorChar != '/') { relaPathInfo = relaPathInfo.Replace('/', IOPath.DirectorySeparatorChar); } while (relaPathInfo.Length > 0 && relaPathInfo[0] == IOPath.DirectorySeparatorChar) { relaPathInfo = relaPathInfo.Substring(1); } if (physPath.Length == 0) { physPathInfo = relaPathInfo; return; // Set values in finally } string physRoot = physPath; try { if (appHost.VirtualFileExists(virtPath)) { physRoot = IOPath.GetDirectoryName(physRoot); if (physRoot == null) { physRoot = String.Empty; } } } catch { // Assume virtPath, physPath & physRoot // specify directories (and not files) } physPathInfo = IOPath.Combine(physRoot, relaPathInfo); } finally { // Now, if all went well, we set: // // SCRIPT_NAME=/dir/test.aspx // SCRIPT_FILENAME=/srv/www/htdocs/dir/test.aspx // PATH_INFO=/foo // PATH_TRANSLATED=/srv/www/htdocs/dir/foo SetParameter("SCRIPT_NAME", virtPath); SetParameter("SCRIPT_FILENAME", physPath); SetParameter("PATH_INFO", virtPathInfo); SetParameter("PATH_TRANSLATED", physPathInfo); } }