-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Introduce shouldFilter flag in OncePerRequestFilter
#35612
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
Conversation
The introduction of shouldFilter allows for intentional filtering.
Usage example:
```java
public class BookingsFilter extends OncePerRequestFilter {
@OverRide
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) { ... }
@OverRide
protected boolean shouldFilter(HttpServletRequest request) throws ServletException {
return request.getRequestURI().startsWith("/booking");
}
}
```
Closes spring-projectsgh-35605
Signed-off-by: Simone Conte <[email protected]>
Signed-off-by: Simone Conte <[email protected]>
Signed-off-by: Simone Conte <[email protected]>
shouldFilter flag in OncePerRequestFilter
Signed-off-by: Simone Conte <[email protected]>
Signed-off-by: Simone Conte <[email protected]>
Signed-off-by: Simone Conte <[email protected]>
|
Filters are already mapped to a specific URL or set of URLs, and it makes sense to narrow that down with an exclude list. So in the example you show, the Could you expand on what you're trying to achieve, including how the |
@rstoyanchev I take it you are referring to the use of In my mind, ExamplesThe way I see it, we would still be mapping the filter using Via URI (as in tests)@Override
protected boolean shouldFilter(HttpServletRequest request) {
return request.getRequestURI().startsWith("/do_not_skip");
}Via other bits of request (e.g. method)@Override
protected boolean shouldFilter(HttpServletRequest request) {
return "POST".equals(request.getMethod());
}Moving forwardHowever, I get that there is already a way to perform filtering, even if it is by URL patterns only. Feel free to close this PR if you think this doesn't fit your architectural design. |
|
Thanks for the extra comments. For mapping Filter's, I was referring to the Servlet API, see for example FilterRegistration, but yes in Boot this is exposed as a FilterRegistrationBean. I will close this for now since OncePerRequestFilter has quite a few options already, and the idea generally is, map the Filter in the Servlet container, and then narrow via exclusions. This should work well even for HTTP methods as there are very few, so you can filter them either as exclusions or as inclusions. We can always reconsider for concrete uses cases. |
The introduction of
shouldFilterallows for intentional filtering.Usage example:
Closes gh-35605