From 44da77513444f8388397f93d057ad1b6187516d3 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Wed, 18 Dec 2019 16:48:49 +0000 Subject: [PATCH] CorsInterceptor skips async dispatch Closes gh-24223 --- .../web/servlet/handler/AbstractHandlerMapping.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java index 28f059926f9c..df7096c5239b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java @@ -36,6 +36,8 @@ import org.springframework.util.PathMatcher; import org.springframework.web.HttpRequestHandler; import org.springframework.web.context.request.WebRequestInterceptor; +import org.springframework.web.context.request.async.WebAsyncManager; +import org.springframework.web.context.request.async.WebAsyncUtils; import org.springframework.web.context.support.WebApplicationObjectSupport; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfigurationSource; @@ -571,6 +573,12 @@ public CorsInterceptor(@Nullable CorsConfiguration config) { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + // Consistent with CorsFilter, ignore ASYNC dispatches + WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request); + if (asyncManager.hasConcurrentResult()) { + return true; + } + return corsProcessor.processRequest(this.config, request, response); }