Update async dispatch check in OncePerRequestFilter

We no longer need to rely on an indirect check since Servlet 3.0 is expected
so we can just check the DispatcherType of the request.

Closes gh-26282
This commit is contained in:
Rossen Stoyanchev 2020-12-17 17:31:44 +00:00
parent 0cf5005a3d
commit 499be70a71
2 changed files with 10 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -145,7 +145,7 @@ public abstract class OncePerRequestFilter extends GenericFilterBean {
* @see WebAsyncManager#hasConcurrentResult()
*/
protected boolean isAsyncDispatch(HttpServletRequest request) {
return WebAsyncUtils.getAsyncManager(request).hasConcurrentResult();
return request.getDispatcherType().equals(DispatcherType.ASYNC);
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,6 +16,7 @@
package org.springframework.web.filter;
import javax.servlet.DispatcherType;
import javax.servlet.FilterChain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -51,6 +52,7 @@ public class CharacterEncodingFilterTests {
request.setCharacterEncoding(ENCODING);
given(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)).willReturn(null);
given(request.getAttribute(filteredName(FILTER_NAME))).willReturn(null);
given(request.getDispatcherType()).willReturn(DispatcherType.REQUEST);
HttpServletResponse response = mock(HttpServletResponse.class);
FilterChain filterChain = mock(FilterChain.class);
@ -71,6 +73,7 @@ public class CharacterEncodingFilterTests {
given(request.getCharacterEncoding()).willReturn(null);
given(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)).willReturn(null);
given(request.getAttribute(filteredName(FILTER_NAME))).willReturn(null);
given(request.getDispatcherType()).willReturn(DispatcherType.REQUEST);
MockHttpServletResponse response = new MockHttpServletResponse();
@ -92,6 +95,7 @@ public class CharacterEncodingFilterTests {
given(request.getCharacterEncoding()).willReturn(ENCODING);
given(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)).willReturn(null);
given(request.getAttribute(filteredName(FILTER_NAME))).willReturn(null);
given(request.getDispatcherType()).willReturn(DispatcherType.REQUEST);
MockHttpServletResponse response = new MockHttpServletResponse();
@ -112,6 +116,7 @@ public class CharacterEncodingFilterTests {
given(request.getCharacterEncoding()).willReturn(null);
given(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)).willReturn(null);
given(request.getAttribute(filteredName(FILTER_NAME))).willReturn(null);
given(request.getDispatcherType()).willReturn(DispatcherType.REQUEST);
MockHttpServletResponse response = new MockHttpServletResponse();
@ -135,6 +140,7 @@ public class CharacterEncodingFilterTests {
given(request.getCharacterEncoding()).willReturn(null);
given(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)).willReturn(null);
given(request.getAttribute(filteredName(CharacterEncodingFilter.class.getName()))).willReturn(null);
given(request.getDispatcherType()).willReturn(DispatcherType.REQUEST);
MockHttpServletResponse response = new MockHttpServletResponse();
@ -156,6 +162,7 @@ public class CharacterEncodingFilterTests {
request.setCharacterEncoding(ENCODING);
given(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)).willReturn(null);
given(request.getAttribute(filteredName(FILTER_NAME))).willReturn(null);
given(request.getDispatcherType()).willReturn(DispatcherType.REQUEST);
HttpServletResponse response = mock(HttpServletResponse.class);
FilterChain filterChain = mock(FilterChain.class);