tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Parker <mp...@voyanttech.com>
Subject [PATCH] forward welcome files
Date Thu, 20 Feb 2003 16:11:56 GMT
My last submission of this patch was heinously wrapped, and buried in a lot of discussion.

This patch will:

- check for the presence of a 'forwardWelcomeFiles' init param. if not present, it's false.
- if 'forwardWelcomeFiles' is true, a request with a trailing slash that resolves to a welcome
file will return the welcome file. if false, it will send a redirect to the welcome file.

Matt


--- DefaultServlet.java.orig    2003-01-07 08:41:16.000000000 -0700
+++ DefaultServlet.java 2003-01-07 08:42:33.000000000 -0700
@@ -169,6 +169,10 @@
      */
     protected String welcomes[] = new String[0];
 
+    /**
+     * Should we redirect or forward for welcome files?
+     */
+    protected boolean forwardWelcomeFiles = false;
 
     /**
      * MD5 message digest provider.
@@ -294,6 +298,13 @@
         } catch (Throwable t) {
             ;
         }
+        try {
+            value = getServletConfig().getInitParameter("forwardWelcomeFiles");
+            if (value != null)
+                forwardWelcomeFiles = (new Boolean(value)).booleanValue();
+        } catch (Throwable t) {
+            ;
+        }
 
         // Sanity check on the specified buffer sizes
         if (input < 256)
@@ -957,11 +968,16 @@
             if (welcomeFileInfo != null) {
                 String redirectPath = welcomeFileInfo.path;
                 String contextPath = request.getContextPath();
-                if ((contextPath != null) && (!contextPath.equals("/"))) {
+                if ((contextPath != null) && (!contextPath.equals("/")) &&
(!forwardWelcomeFiles)) {
                     redirectPath = contextPath + redirectPath;
                 }
                 redirectPath = appendParameters(request, redirectPath);
-                response.sendRedirect(redirectPath);
+                if (forwardWelcomeFiles) {
+                   request.getRequestDispatcher(redirectPath).forward(request, response);
+                }
+                else {
+                   response.sendRedirect(redirectPath);
+                }
                 return;
             }

--- web.xml.orig        2003-01-07 08:58:09.000000000 -0700
+++ web.xml     2003-01-07 08:50:13.000000000 -0700
@@ -39,6 +39,9 @@
   <!--   readonly            Is this context "read only", so HTTP           -->
   <!--                       commands like PUT and DELETE are               -->
   <!--                       rejected?  [true]                              -->
+  <!--                                                                      -->
+  <!--   forwardWelcomeFiles Should welcome files be forwarded instead      -->
+  <!--                       of being redirected? [false]                   -->
       <servlet>
         <servlet-name>default</servlet-name>




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message