Skip to content

Update OncePerRequestFilter.isAsyncDispatch to use HttpServletRequest.getDispatcherType() #26282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rwinch opened this issue Dec 15, 2020 · 4 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@rwinch
Copy link
Member

rwinch commented Dec 15, 2020

To ensure that the OncePerRequestFilter works when the servlet API is used directly it would be nice to update OncePerRequestFilter.isAsyncDispatch to use HttpServletRequest.getDispatcherType()

@Override
protected boolean isAsyncDispatch(HttpServletRequest request) {
    return request.getDispatcherType() == DispatcherType.ASYNC;
}

See spring-projects/spring-security#4211

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 15, 2020
@rstoyanchev rstoyanchev self-assigned this Dec 17, 2020
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 17, 2020
@rstoyanchev rstoyanchev added this to the 5.3.3 milestone Dec 17, 2020
@slyoldfox
Copy link

@rstoyanchev I just had this NPE in a unit test when moving from Spring Boot 2.4.1 to Spring Boot 2.4.3.

It might be safer to flip the arguments in:

	protected boolean isAsyncDispatch(HttpServletRequest request) {
		return request.getDispatcherType().equals(DispatcherType.ASYNC);
	}

@sbrannen
Copy link
Member

@slyoldfox, can you please create a new GitHub issue to track that NPE?

@sbrannen
Copy link
Member

@slyoldfox, out of curiosity, are you invoking org.springframework.mock.web.MockHttpServletRequest.setDispatcherType(DispatcherType) with a null value somewhere in your tests?

@slyoldfox
Copy link

@sbrannen it was a silly mockito mock of HttpServletRequest.class I have outlined it in the linked issue, thanks for the update :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants