From a0b02786738019e641fa89c3e8668869f4b9e0c4 Mon Sep 17 00:00:00 2001 From: timw Date: Mon, 4 Oct 2010 20:37:11 +0000 Subject: [PATCH] More fixes for https://issues.apache.org/bugzilla/show_bug.cgi?id=50026 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 | 15 +++++++++++++-- java/org/apache/catalina/servlets/WebdavServlet.java | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/java/org/apache/catalina/servlets/DefaultServlet.java b/java/org/apache/catalina/servlets/DefaultServlet.java index 5e5b126d8..30af597fe 100644 --- a/java/org/apache/catalina/servlets/DefaultServlet.java +++ b/java/org/apache/catalina/servlets/DefaultServlet.java @@ -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); } } diff --git a/java/org/apache/catalina/servlets/WebdavServlet.java b/java/org/apache/catalina/servlets/WebdavServlet.java index fb4054ca8..fe2f5918e 100644 --- a/java/org/apache/catalina/servlets/WebdavServlet.java +++ b/java/org/apache/catalina/servlets/WebdavServlet.java @@ -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 -- 2.11.0