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
This commit is contained in:
Arjen Poutsma 2020-12-08 11:59:36 +01:00
parent 3b92d45984
commit cb2b141d31
1 changed files with 14 additions and 0 deletions

View File

@ -40,8 +40,11 @@ import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.MultiValueMap;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.async.AsyncWebRequest;
import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.context.request.async.DeferredResultProcessingInterceptor;
import org.springframework.web.context.request.async.WebAsyncManager;
import org.springframework.web.context.request.async.WebAsyncUtils;
import org.springframework.web.servlet.ModelAndView;
@ -54,6 +57,16 @@ import org.springframework.web.servlet.ModelAndView;
*/
final class DefaultAsyncServerResponse extends ErrorHandlingServerResponse implements AsyncServerResponse {
private static final DeferredResultProcessingInterceptor CLEAR_PATTERN_ATTRIBUTE_INTERCEPTOR =
new DeferredResultProcessingInterceptor() {
@Override
public <T> void postProcess(NativeWebRequest request, DeferredResult<T> deferredResult,
Object concurrentResult) {
request.removeAttribute(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE,
RequestAttributes.SCOPE_REQUEST);
}
};
static final boolean reactiveStreamsPresent = ClassUtils.isPresent(
"org.reactivestreams.Publisher", DefaultAsyncServerResponse.class.getClassLoader());
@ -128,6 +141,7 @@ final class DefaultAsyncServerResponse extends ErrorHandlingServerResponse imple
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
AsyncWebRequest asyncWebRequest = WebAsyncUtils.createAsyncWebRequest(request, response);
asyncManager.setAsyncWebRequest(asyncWebRequest);
asyncManager.registerDeferredResultInterceptors(CLEAR_PATTERN_ATTRIBUTE_INTERCEPTOR);
try {
asyncManager.startDeferredResultProcessing(deferredResult);
}