More fixes for https://issues.apache.org/bugzilla/show_bug.cgi?id=50026
authortimw <timw@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 4 Oct 2010 20:37:11 +0000 (20:37 +0000)
committertimw <timw@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 4 Oct 2010 20:37:11 +0000 (20:37 +0000)
Calculating path prefix used in listings correctly so links in listings produced by WebdavServlet mounted to a subpath are correct.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1004415 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/servlets/DefaultServlet.java
java/org/apache/catalina/servlets/WebdavServlet.java

index 5e5b126..30af597 100644 (file)
@@ -374,6 +374,18 @@ public class DefaultServlet
 
 
     /**
+     * Determines the appropriate path to prepend resources with
+     * when generating directory listings. Depending on the behaviour of 
+     * {@link #getRelativePath(HttpServletRequest)} this will change.
+     * @param request the request to determine the path for
+     * @return the prefix to apply to all resources in the listing.
+     */
+    protected String getPathPrefix(final HttpServletRequest request) {
+        return request.getContextPath();
+    }
+
+
+    /**
      * Process a GET request for the specified resource.
      *
      * @param request The servlet request we are processing
@@ -890,8 +902,7 @@ public class DefaultServlet
 
                 if (serveContent) {
                     // Serve the directory browser
-                    renderResult =
-                        render(request.getContextPath(), cacheEntry);
+                    renderResult = render(getPathPrefix(request), cacheEntry);
                 }
 
             }
index fb4054c..fe2f591 100644 (file)
@@ -428,6 +428,20 @@ public class WebdavServlet
 
 
     /**
+     * Determines the prefix for standard directory GET listings.
+     */
+    @Override
+    protected String getPathPrefix(final HttpServletRequest request) {
+        // Repeat the servlet path (e.g. /webdav/) in the listing path
+        String contextPath = request.getContextPath();
+        if (request.getServletPath() !=  null) {
+            contextPath = contextPath + request.getServletPath();
+        }
+        return contextPath;
+    }
+
+
+    /**
      * OPTIONS Method.
      *
      * @param req The request