diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Dispatcher.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Dispatcher.java index 81cd58d8b007..df7850d9b1eb 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Dispatcher.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Dispatcher.java @@ -410,7 +410,7 @@ public Object getAttribute(String key) case INCLUDE_CONTEXT_PATH: { ContextHandler.Context context = _baseRequest.getContext(); - return context == null ? null : context.getContextHandler().getContextPathEncoded(); + return context == null ? null : context.getContextHandler().getRequestContextPath(); } case INCLUDE_QUERY_STRING: return _query; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java index e1c004216662..4312ab0ef1e4 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java @@ -794,14 +794,7 @@ public String getContextPath() if (context == null) return null; - // For some reason the spec requires the context path to be encoded (unlike getServletPath). - String contextPath = context.getContextHandler().getContextPathEncoded(); - - // For the root context, the spec requires that the empty string is returned instead of the leading '/' - // which is included in the pathInContext - if (URIUtil.SLASH.equals(contextPath)) - return ""; - return contextPath; + return context.getContextHandler().getRequestContextPath(); } /** Get the path in the context. diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java index 3206f4a0d1a7..3376182434f0 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java @@ -439,8 +439,6 @@ public void doScope(String target, Request baseRequest, HttpServletRequest reque // Get the base requests final ServletPathMapping old_servlet_path_mapping = baseRequest.getServletPathMapping(); - DispatcherType type = baseRequest.getDispatcherType(); - ServletHolder servletHolder = null; UserIdentity.Scope oldScope = null; @@ -472,8 +470,7 @@ public void doScope(String target, Request baseRequest, HttpServletRequest reque if (oldScope != null) baseRequest.setUserIdentityScope(oldScope); - if (!(DispatcherType.INCLUDE.equals(type))) - baseRequest.setServletPathMapping(old_servlet_path_mapping); + baseRequest.setServletPathMapping(old_servlet_path_mapping); } } diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/IncludedServletTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/IncludedServletTest.java index c7794d7e99de..c3413e93ba8c 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/IncludedServletTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/IncludedServletTest.java @@ -42,7 +42,6 @@ import org.hamcrest.Matchers; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; @@ -108,12 +107,13 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se private void dumpAttrs(String tag, HttpServletRequest req, ServletOutputStream out) throws IOException { - out.println(String.format("%s: %s='%s'", tag, RequestDispatcher.INCLUDE_CONTEXT_PATH, - req.getAttribute(RequestDispatcher.INCLUDE_CONTEXT_PATH))); - out.println(String.format("%s: %s='%s'", tag, RequestDispatcher.INCLUDE_SERVLET_PATH, - req.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH))); - out.println(String.format("%s: %s='%s'", tag, RequestDispatcher.INCLUDE_PATH_INFO, - req.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO))); + String contextPath = (String)req.getAttribute(RequestDispatcher.INCLUDE_CONTEXT_PATH); + String servletPath = (String)req.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH); + String pathInfo = (String)req.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO); + + out.println(String.format("%s: %s='%s'", tag, RequestDispatcher.INCLUDE_CONTEXT_PATH, contextPath)); + out.println(String.format("%s: %s='%s'", tag, RequestDispatcher.INCLUDE_SERVLET_PATH, servletPath)); + out.println(String.format("%s: %s='%s'", tag, RequestDispatcher.INCLUDE_PATH_INFO, pathInfo)); } } @@ -221,7 +221,6 @@ private String getPotentialBody(HttpURLConnection connection) } } - @Disabled // TODO: complete merge of PR #5058. @Test public void testIncludeAttributes() throws IOException {