This is an automated email from the ASF dual-hosted git repository.
markt 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 511ffac20f Servlet 6.2 spec changes for
HttpServletRequest.getContextPath()
511ffac20f is described below
commit 511ffac20f5cc332153a7540390484150aed67cd
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Apr 23 11:37:57 2025 +0100
Servlet 6.2 spec changes for HttpServletRequest.getContextPath()
While the relaxed requirements would allow a much simpler implementation
of returning the canonical context path (obtained from
getServletContext().getContextPath()), that approach complicates some
Tomcat internals particularly around AsyncContext.dispath() when the
request URI contains encoded / (%2F) characters.
The simpler implementation isn't worth the risk of creating regressions.
---
java/jakarta/servlet/http/HttpServletRequest.java | 10 +++++++---
java/org/apache/catalina/connector/Request.java | 6 ++++++
java/org/apache/catalina/connector/RequestFacade.java | 6 ++++++
3 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/java/jakarta/servlet/http/HttpServletRequest.java
b/java/jakarta/servlet/http/HttpServletRequest.java
index daff471fb7..a325da05ce 100644
--- a/java/jakarta/servlet/http/HttpServletRequest.java
+++ b/java/jakarta/servlet/http/HttpServletRequest.java
@@ -77,8 +77,8 @@ public interface HttpServletRequest extends ServletRequest {
* <code>Date</code> object. Use this method with headers that contain
dates, such as
* <code>If-Modified-Since</code>.
* <p>
- * The date is returned as the number of milliseconds since January 1,
1970 GMT. The header name
- * is case-insensitive.
+ * The date is returned as the number of milliseconds since January 1,
1970 GMT. The header name is
+ * case-insensitive.
* <p>
* If the request did not have a header of the specified name, this method
returns -1. If the header can't be
* converted to a date, the method throws an
<code>IllegalArgumentException</code>.
@@ -239,7 +239,11 @@ public interface HttpServletRequest extends ServletRequest
{
/**
* Returns the portion of the request URI that indicates the context of
the request. The context path always comes
* first in a request URI. The path starts with a "/" character but does
not end with a "/" character. For servlets
- * in the default (root) context, this method returns "". The container
does not decode this string.
+ * in the default (root) context, this method returns "".
+ * <p>
+ * The value returned will be suitable for inclusion in a URI. It will be
equivalent to the value provided by the
+ * user agent but it may not be identical to the value provided by the
user agent. Path parameters will be removed,
+ * the path may be normalized or partially normalized and optional %nn
encoding may be decoded or partially decoded.
*
* @return a <code>String</code> specifying the portion of the request URI
that indicates the context of the request
*/
diff --git a/java/org/apache/catalina/connector/Request.java
b/java/org/apache/catalina/connector/Request.java
index ef9345ba4f..a1738febe9 100644
--- a/java/org/apache/catalina/connector/Request.java
+++ b/java/org/apache/catalina/connector/Request.java
@@ -1841,6 +1841,12 @@ public class Request implements HttpServletRequest {
}
+ /**
+ * {@inheritDoc}
+ * <p>
+ * Tomcat neither normalizes nor decodes the returned value. It will be
identical to the part of the request URI
+ * provided by the user agent that was used to determine the context path.
+ */
@Override
public String getContextPath() {
int lastSlash = mappingData.contextSlashCount;
diff --git a/java/org/apache/catalina/connector/RequestFacade.java
b/java/org/apache/catalina/connector/RequestFacade.java
index 54be51b02d..4a8b3b99d7 100644
--- a/java/org/apache/catalina/connector/RequestFacade.java
+++ b/java/org/apache/catalina/connector/RequestFacade.java
@@ -341,6 +341,12 @@ public class RequestFacade implements HttpServletRequest {
}
+ /**
+ * {@inheritDoc}
+ * <p>
+ * Tomcat neither normalizes nor decodes the returned value. It will be
identical to the part of the request URI
+ * provided by the user agent that was used to determine the context path.
+ */
@Override
public String getContextPath() {
checkFacade();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]