From 47a18a152f5149de5b4e09ff73b172c4c36f7a57 Mon Sep 17 00:00:00 2001 From: hejingming368-max Date: Wed, 18 Nov 2026 16:44:52 +0800 Subject: [PATCH] Use container request and response for async dispatch Start async processing with the original container request and response. Supplying wrappers whose request URI includes a forwarded prefix causes Jetty to dispatch to the prefixed path instead of the handler path. Closes gh-37681 Signed-off-by: hejingming368-max --- .../async/StandardServletAsyncWebRequest.java | 2 +- .../StandardServletAsyncWebRequestTests.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java b/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java index 19d50236c23a..b4f219b1d212 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java @@ -155,7 +155,7 @@ public void startAsync() { Assert.state(this.state == State.ASYNC, "Cannot start async: [" + this.state + "]"); } - this.asyncContext = getRequest().startAsync(getRequest(), getResponse()); + this.asyncContext = getRequest().startAsync(); this.asyncContext.addListener(this); if (this.timeout != null) { this.asyncContext.setTimeout(this.timeout); diff --git a/spring-web/src/test/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequestTests.java b/spring-web/src/test/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequestTests.java index ec5d773d2dbf..f510aa1755be 100644 --- a/spring-web/src/test/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequestTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequestTests.java @@ -18,7 +18,10 @@ import java.util.function.Consumer; +import jakarta.servlet.AsyncContext; import jakarta.servlet.AsyncEvent; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -31,6 +34,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; /** * Tests for {@link StandardServletAsyncWebRequest}. @@ -79,6 +83,20 @@ void startAsync() { assertThat(context.getListeners()).containsExactly(asyncRequest); } + @Test + void startAsyncUsesContainerRequestAndResponse() { + HttpServletRequest request = mock(HttpServletRequest.class); + HttpServletResponse response = mock(HttpServletResponse.class); + AsyncContext asyncContext = mock(AsyncContext.class); + when(request.isAsyncSupported()).thenReturn(true); + when(request.startAsync()).thenReturn(asyncContext); + StandardServletAsyncWebRequest asyncRequest = new StandardServletAsyncWebRequest(request, response); + + asyncRequest.startAsync(); + + verify(request).startAsync(); + } + @Test void startAsyncMultipleTimes() { asyncRequest.startAsync();