This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/11.0.x by this push:
new a4259bcaf2 Add option to serve resources from subpath only with WebDAV
Servlet
a4259bcaf2 is described below
commit a4259bcaf2a6461c358e5b77746482aefeba1178
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 | 8 ++++++++
2 files changed, 29 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 3258e25c76..1bc004509c 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -105,6 +105,14 @@
issues do not "pop up" wrt. others).
-->
<section name="Tomcat 11.0.2 (markt)" rtext="in development">
+ <subsection name="Catalina">
+ <changelog>
+ <add>
+ Add option to serve resources from subpath only with WebDAV Servlet
like
+ with DefaultServlet. (michaelo)
+ </add>
+ </changelog>
+ </subsection>
<subsection name="Coyote">
<changelog>
<fix>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]