billbarker 2003/03/12 22:17:53 Modified: util/java/org/apache/tomcat/util/http/mapper Mapper.java Log: Initial support to do a redirect to a directory where the URL doesn't end in '/'. This prevents browsers from becoming confused when they get a 401 response for e.g. /foo. With this turned on, the browser will get a 302 response to /foo/ before authentication is checked. It is currently off by default to save the cost of a JNDI lookup on each request. Revision Changes Path 1.11 +39 -0 jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/mapper/Mapper.java Index: Mapper.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/mapper/Mapper.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- Mapper.java 7 Mar 2003 16:03:33 -0000 1.10 +++ Mapper.java 13 Mar 2003 06:17:53 -0000 1.11 @@ -97,6 +97,12 @@ */ protected boolean processWelcomeResources = true; + /** + * Flag indicating that we should redirect to a directory when the URL + * doesn't end in a '/'. It overrided the Authenticator, so the redirect + * done before authentication. + */ + protected boolean redirectDirectories = false; // --------------------------------------------------------- Public Methods @@ -143,6 +149,21 @@ this.processWelcomeResources = processWelcomeResources; } + /** + * Get the flag that indicates if we redirect to directories that don't + * end a '/'. + */ + public boolean getRedirectDirectories() { + return redirectDirectories; + } + + /** + * Set the flag that indicates if we redirect to directories that don't + * end in a '/'. + */ + public void setRedirectDirectories(boolean rd) { + redirectDirectories = rd; + } /** * Add a new host to the mapper. @@ -570,6 +591,24 @@ (path.getBuffer(), path.getStart(), path.getLength()); mappingData.wrapperPath.setChars (path.getBuffer(), path.getStart(), path.getLength()); + } + if( redirectDirectories ) { + char[] buf = path.getBuffer(); + if( context.resources != null && buf[pathEnd -1 ] != '/') { + Object file = null; + try { + file = context.resources.lookup(path.toString()); + } catch(NamingException nex) { + // Swallow, since someone else handles the 404 + } + if(file != null && file instanceof DirContext ) { + CharChunk dirPath = path.getClone(); + dirPath.append('/'); + mappingData.redirectPath.setChars + (dirPath.getBuffer(), dirPath.getStart(), + dirPath.getLength()); + } + } } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]