funkman     2003/11/21 11:00:52

  Modified:    catalina/src/conf web.xml
               catalina/src/share/org/apache/catalina/servlets
                        DefaultServlet.java
  Log:
  Allow welcome files and directory redirects to be urlEncoded to satisfy
  many tomcat-user complaints. I thought there were Bugzilla reports
  too but can't find them
  
  Default behavior is to not encode for backwards compatibility.
  
  Revision  Changes    Path
  1.51      +3 -0      jakarta-tomcat-4.0/catalina/src/conf/web.xml
  
  Index: web.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/conf/web.xml,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- web.xml   18 Jun 2003 20:52:54 -0000      1.50
  +++ web.xml   21 Nov 2003 19:00:52 -0000      1.51
  @@ -39,6 +39,9 @@
     <!--   readonly            Is this context "read only", so HTTP           -->
     <!--                       commands like PUT and DELETE are               -->
     <!--                       rejected?  [true]                              -->
  +  <!--                                                                      -->
  +  <!--   encodeRedirects     Call encodeRedirectURL() on welcomefile or     -->
  +  <!--                       directory redirects. [false]                   -->
   
       <servlet>
           <servlet-name>default</servlet-name>
  
  
  
  1.60      +46 -28    
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/DefaultServlet.java
  
  Index: DefaultServlet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/DefaultServlet.java,v
  retrieving revision 1.59
  retrieving revision 1.60
  diff -u -r1.59 -r1.60
  --- DefaultServlet.java       8 Jan 2003 19:38:05 -0000       1.59
  +++ DefaultServlet.java       21 Nov 2003 19:00:52 -0000      1.60
  @@ -165,6 +165,12 @@
   
   
       /**
  +     * Calls encodeRedirectURL on redirects? default=false
  +     */
  +    protected boolean encodeRedirects = false;
  +
  +
  +    /**
        * The set of welcome files for this web application
        */
       protected String welcomes[] = new String[0];
  @@ -294,6 +300,12 @@
           } catch (Throwable t) {
               ;
           }
  +        try {
  +            value = getServletConfig().getInitParameter("encodeRedirects");
  +            encodeRedirects = (new Boolean(value)).booleanValue();
  +        } catch (Throwable t) {
  +            ;
  +        }
   
           // Sanity check on the specified buffer sizes
           if (input < 256)
  @@ -627,12 +639,12 @@
   
   
       /**
  -     * Handle a partial PUT.  New content specified in request is appended to 
  -     * existing content in oldRevisionContent (if present). This code does 
  +     * Handle a partial PUT.  New content specified in request is appended to
  +     * existing content in oldRevisionContent (if present). This code does
        * not support simultaneous partial updates to the same resource.
        */
  -    protected File executePartialPut(HttpServletRequest req, Range range, 
  -                                     String path) 
  +    protected File executePartialPut(HttpServletRequest req, Range range,
  +                                     String path)
           throws IOException {
   
           // Append data specified in ranges to existing content for this
  @@ -648,7 +660,7 @@
               contentFile.deleteOnExit();
           }
   
  -        RandomAccessFile randAccessContentFile = 
  +        RandomAccessFile randAccessContentFile =
               new RandomAccessFile(contentFile, "rw");
   
           Resource oldResource = null;
  @@ -661,8 +673,8 @@
   
           // Copy data in oldRevisionContent to contentFile
           if (oldResource != null) {
  -            BufferedInputStream bufOldRevStream = 
  -                new BufferedInputStream(oldResource.streamContent(), 
  +            BufferedInputStream bufOldRevStream =
  +                new BufferedInputStream(oldResource.streamContent(),
                                           BUFFER_SIZE);
   
               int numBytesRead;
  @@ -763,9 +775,9 @@
                                        ResourceInfo resourceInfo)
           throws IOException {
   
  -        return checkIfMatch(request, response, resourceInfo) 
  -            && checkIfModifiedSince(request, response, resourceInfo) 
  -            && checkIfNoneMatch(request, response, resourceInfo) 
  +        return checkIfMatch(request, response, resourceInfo)
  +            && checkIfModifiedSince(request, response, resourceInfo)
  +            && checkIfNoneMatch(request, response, resourceInfo)
               && checkIfUnmodifiedSince(request, response, resourceInfo);
   
       }
  @@ -784,7 +796,7 @@
           } else if (resourceInfo.weakETag != null) {
               return resourceInfo.weakETag;
           } else {
  -            return "W/\"" + resourceInfo.length + "-" 
  +            return "W/\"" + resourceInfo.length + "-"
                   + resourceInfo.date + "\"";
           }
       }
  @@ -921,7 +933,7 @@
           ResourceInfo resourceInfo = new ResourceInfo(path, resources);
   
           if (!resourceInfo.exists) {
  -            response.sendError(HttpServletResponse.SC_NOT_FOUND, 
  +            response.sendError(HttpServletResponse.SC_NOT_FOUND,
                                  request.getRequestURI());
               return;
           }
  @@ -930,7 +942,7 @@
           // ends with "/" or "\", return NOT FOUND
           if (!resourceInfo.collection) {
               if (path.endsWith("/") || (path.endsWith("\\"))) {
  -                response.sendError(HttpServletResponse.SC_NOT_FOUND, 
  +                response.sendError(HttpServletResponse.SC_NOT_FOUND,
                                      request.getRequestURI());
                   return;
               }
  @@ -949,6 +961,9 @@
                   if (!(redirectPath.endsWith("/")))
                       redirectPath = redirectPath + "/";
                   redirectPath = appendParameters(request, redirectPath);
  +                if (encodeRedirects) {
  +                    redirectPath = response.encodeRedirectURL(redirectPath);
  +                }
                   response.sendRedirect(redirectPath);
                   return;
               }
  @@ -961,6 +976,9 @@
                       redirectPath = contextPath + redirectPath;
                   }
                   redirectPath = appendParameters(request, redirectPath);
  +                if (encodeRedirects) {
  +                    redirectPath = response.encodeRedirectURL(redirectPath);
  +                }
                   response.sendRedirect(redirectPath);
                   return;
               }
  @@ -970,7 +988,7 @@
               // Checking If headers
               boolean included =
                   (request.getAttribute(Globals.CONTEXT_PATH_ATTR) != null);
  -            if (!included 
  +            if (!included
                   && !checkIfHeaders(request, response, resourceInfo)) {
                   return;
               }
  @@ -1183,7 +1201,7 @@
   
           try {
               range.start = Long.parseLong(rangeHeader.substring(0, dashPos));
  -            range.end = 
  +            range.end =
                   Long.parseLong(rangeHeader.substring(dashPos + 1, slashPos));
               range.length = Long.parseLong
                   (rangeHeader.substring(slashPos + 1, rangeHeader.length()));
  @@ -1300,7 +1318,7 @@
                       currentRange.start = fileLength + offset;
                       currentRange.end = fileLength - 1;
                   } catch (NumberFormatException e) {
  -                    response.addHeader("Content-Range", 
  +                    response.addHeader("Content-Range",
                                          "bytes */" + fileLength);
                       response.sendError
                           (HttpServletResponse
  @@ -1320,7 +1338,7 @@
                       else
                           currentRange.end = fileLength - 1;
                   } catch (NumberFormatException e) {
  -                    response.addHeader("Content-Range", 
  +                    response.addHeader("Content-Range",
                                          "bytes */" + fileLength);
                       response.sendError
                           (HttpServletResponse
  @@ -1555,7 +1573,7 @@
        * @param response The servlet response we are creating
        * @param resourceInfo File object
        * @return boolean true if the resource meets the specified condition,
  -     * and false if the condition is not satisfied, in which case request 
  +     * and false if the condition is not satisfied, in which case request
        * processing is stopped
        */
       private boolean checkIfMatch(HttpServletRequest request,
  @@ -1600,7 +1618,7 @@
        * @param response The servlet response we are creating
        * @param resourceInfo File object
        * @return boolean true if the resource meets the specified condition,
  -     * and false if the condition is not satisfied, in which case request 
  +     * and false if the condition is not satisfied, in which case request
        * processing is stopped
        */
       private boolean checkIfModifiedSince(HttpServletRequest request,
  @@ -1611,10 +1629,10 @@
               long headerValue = request.getDateHeader("If-Modified-Since");
               long lastModified = resourceInfo.date;
               if (headerValue != -1) {
  -    
  +
                   // If an If-None-Match header has been specified, if modified since
                   // is ignored.
  -                if ((request.getHeader("If-None-Match") == null) 
  +                if ((request.getHeader("If-None-Match") == null)
                       && (lastModified <= headerValue + 1000)) {
                       // The entity has not been modified since the date
                       // specified by the client. This is not an error case.
  @@ -1637,7 +1655,7 @@
        * @param response The servlet response we are creating
        * @param resourceInfo File object
        * @return boolean true if the resource meets the specified condition,
  -     * and false if the condition is not satisfied, in which case request 
  +     * and false if the condition is not satisfied, in which case request
        * processing is stopped
        */
       private boolean checkIfNoneMatch(HttpServletRequest request,
  @@ -1653,7 +1671,7 @@
   
               if (!headerValue.equals("*")) {
   
  -                StringTokenizer commaTokenizer = 
  +                StringTokenizer commaTokenizer =
                       new StringTokenizer(headerValue, ",");
   
                   while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) {
  @@ -1695,7 +1713,7 @@
        * @param response The servlet response we are creating
        * @param resourceInfo File object
        * @return boolean true if the resource meets the specified condition,
  -     * and false if the condition is not satisfied, in which case request 
  +     * and false if the condition is not satisfied, in which case request
        * processing is stopped
        */
       private boolean checkIfUnmodifiedSince(HttpServletRequest request,
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to