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 ed6b8525e7b..d84f7e5713e 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 @@ -2258,7 +2258,15 @@ public class Request implements HttpServletRequest _async=new AsyncContextState(state); AsyncContextEvent event = new AsyncContextEvent(_context,_async,state,this,servletRequest,servletResponse); event.setDispatchContext(getServletContext()); - event.setDispatchPath(URIUtil.encodePath(URIUtil.addPaths(getServletPath(),getPathInfo()))); + + String uri = ((HttpServletRequest)servletRequest).getRequestURI(); + if (uri.startsWith(_contextPath)) + uri = uri.substring(_contextPath.length()); + else + // TODO probably need to strip encoded context from requestURI, but will do this for now: + uri = URIUtil.encodePath(URIUtil.addPaths(getServletPath(),getPathInfo())); + + event.setDispatchPath(uri); state.startAsync(event); return _async; } diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextTest.java index 884396bcd62..ed11db421a9 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextTest.java @@ -261,7 +261,6 @@ public class AsyncContextTest } @Test - @Ignore("See https://github.com/eclipse/jetty.project/issues/1618") public void testDispatchAsyncContext_SelfEncodedUrl() throws Exception { String request = "GET /ctx/self/hello%2fthere?dispatch=true HTTP/1.1\r\n" + @@ -274,8 +273,8 @@ public class AsyncContextTest String responseBody = response.getContent(); - assertThat("servlet request uri initial", responseBody, containsString("doGet:REQUEST.requestURI:/ctx/self/hello%2fthere")); - assertThat("servlet request uri async", responseBody, containsString("doGet:ASYNC.requestURI:/ctx/self/hello%2fthere")); + assertThat("servlet request uri initial", responseBody, containsString("doGet.REQUEST.requestURI:/ctx/self/hello%2fthere")); + assertThat("servlet request uri async", responseBody, containsString("doGet.ASYNC.requestURI:/ctx/self/hello%2fthere")); } @Test @@ -353,7 +352,6 @@ public class AsyncContextTest "\r\n"; String responseString = _connector.getResponse(request); - System.err.println(responseString); HttpTester.Response response = HttpTester.parseResponse(responseString); assertThat("Response.status", response.getStatus(), is(HttpServletResponse.SC_OK));