This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new f5601ff240 Add option to serve resources from subpath only with WebDAV
Servlet
f5601ff240 is described below
commit f5601ff240e2c7f8cb98fe79e8e30f53b731edfd
Author: Michael Osipov <[email protected]>
AuthorDate: Wed Nov 13 11:48:00 2024 +0100
Add option to serve resources from subpath only with WebDAV Servlet
---
.../apache/catalina/servlets/WebdavServlet.java | 23 ++++++++++++++++++++--
webapps/docs/changelog.xml | 4 ++++
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/java/org/apache/catalina/servlets/WebdavServlet.java
b/java/org/apache/catalina/servlets/WebdavServlet.java
index 0766e91b84..8de9008314 100644
--- a/java/org/apache/catalina/servlets/WebdavServlet.java
+++ b/java/org/apache/catalina/servlets/WebdavServlet.java
@@ -74,11 +74,12 @@ import org.xml.sax.SAXException;
/**
* Servlet which adds support for <a
href="https://tools.ietf.org/html/rfc4918">WebDAV</a>
* <a href="https://tools.ietf.org/html/rfc4918#section-18">level 3</a>. All
the basic HTTP requests are handled by the
- * DefaultServlet. The WebDAVServlet must not be used as the default servlet
(ie mapped to '/') as it will not work in
+ * DefaultServlet. The WebdavServlet must not be used as the default servlet
(ie mapped to '/') as it will not work in
* this configuration.
* <p>
* Mapping a subpath (e.g. <code>/webdav/*</code> to this servlet has the
effect of re-mounting the entire web
- * application under that sub-path, with WebDAV access to all the resources.
The <code>WEB-INF</code> and
+ * application under that sub-path, with WebDAV access to all the resources.
To restore the DefaultServlet
+ * behavior set <code>serveSubpathOnly</code> to <code>true</code>. The
<code>WEB-INF</code> and
* <code>META-INF</code> directories are protected in this re-mounted resource
tree.
* <p>
* To enable WebDAV for a context add the following to web.xml:
@@ -247,6 +248,12 @@ public class WebdavServlet extends DefaultServlet
implements PeriodicEventListen
*/
private boolean strictIfProcessing = true;
+ /**
+ * Serve resources from the mounted subpath only, restoring the behavior of
+ * {@code DefaultServlet}.
+ */
+ private boolean serveSubpathOnly = false;
+
/**
* Property store used for storage of dead properties.
@@ -285,6 +292,10 @@ public class WebdavServlet extends DefaultServlet
implements PeriodicEventListen
strictIfProcessing =
Boolean.parseBoolean(getServletConfig().getInitParameter("strictIfProcessing"));
}
+ if (getServletConfig().getInitParameter("serveSubpathOnly") != null) {
+ serveSubpathOnly =
Boolean.parseBoolean(getServletConfig().getInitParameter("serveSubpathOnly"));
+ }
+
String propertyStore =
getServletConfig().getInitParameter("propertyStore");
if (propertyStore != null) {
try {
@@ -686,6 +697,10 @@ public class WebdavServlet extends DefaultServlet
implements PeriodicEventListen
*/
@Override
protected String getRelativePath(HttpServletRequest request, boolean
allowEmptyPath) {
+ if (serveSubpathOnly) {
+ return super.getRelativePath(request, allowEmptyPath);
+ }
+
String pathInfo;
if (request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) !=
null) {
@@ -712,6 +727,10 @@ public class WebdavServlet extends DefaultServlet
implements PeriodicEventListen
@Override
protected String getPathPrefix(final HttpServletRequest request) {
+ if (serveSubpathOnly) {
+ return super.getPathPrefix(request);
+ }
+
// Repeat the servlet path (e.g. /webdav/) in the listing path
String contextPath = request.getContextPath();
if (request.getServletPath() != null) {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 56b87edce9..0fe94c3a63 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -126,6 +126,10 @@
Remove default value (was <code>catalina</code>) for the
<code>secret</code> init parameter of the WebDAV Servlet. (remm)
</update>
+ <add>
+ Add option to serve resources from subpath only with WebDAV Servlet
like
+ with DefaultServlet. (michaelo)
+ </add>
<!-- Entries for backport and removal before 12.0.0-M1 below this line
-->
</changelog>
</subsection>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]