Skip to content

Commit cb2b141

Browse files
committed
Clear path pattern after async result
This commit makes sure that the matching pattern attributes is cleared when an async result has been obtained, so that the subsequent dispatch starts from scratch. Closes gh-26239
1 parent 3b92d45 commit cb2b141

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultAsyncServerResponse.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@
4040
import org.springframework.util.Assert;
4141
import org.springframework.util.ClassUtils;
4242
import org.springframework.util.MultiValueMap;
43+
import org.springframework.web.context.request.NativeWebRequest;
44+
import org.springframework.web.context.request.RequestAttributes;
4345
import org.springframework.web.context.request.async.AsyncWebRequest;
4446
import org.springframework.web.context.request.async.DeferredResult;
47+
import org.springframework.web.context.request.async.DeferredResultProcessingInterceptor;
4548
import org.springframework.web.context.request.async.WebAsyncManager;
4649
import org.springframework.web.context.request.async.WebAsyncUtils;
4750
import org.springframework.web.servlet.ModelAndView;
@@ -54,6 +57,16 @@
5457
*/
5558
final class DefaultAsyncServerResponse extends ErrorHandlingServerResponse implements AsyncServerResponse {
5659

60+
private static final DeferredResultProcessingInterceptor CLEAR_PATTERN_ATTRIBUTE_INTERCEPTOR =
61+
new DeferredResultProcessingInterceptor() {
62+
@Override
63+
public <T> void postProcess(NativeWebRequest request, DeferredResult<T> deferredResult,
64+
Object concurrentResult) {
65+
request.removeAttribute(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE,
66+
RequestAttributes.SCOPE_REQUEST);
67+
}
68+
};
69+
5770
static final boolean reactiveStreamsPresent = ClassUtils.isPresent(
5871
"org.reactivestreams.Publisher", DefaultAsyncServerResponse.class.getClassLoader());
5972

@@ -128,6 +141,7 @@ static void writeAsync(HttpServletRequest request, HttpServletResponse response,
128141
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
129142
AsyncWebRequest asyncWebRequest = WebAsyncUtils.createAsyncWebRequest(request, response);
130143
asyncManager.setAsyncWebRequest(asyncWebRequest);
144+
asyncManager.registerDeferredResultInterceptors(CLEAR_PATTERN_ATTRIBUTE_INTERCEPTOR);
131145
try {
132146
asyncManager.startDeferredResultProcessing(deferredResult);
133147
}

0 commit comments

Comments
 (0)