-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Closed as not planned
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: supersededAn issue that has been superseded by anotherAn issue that has been superseded by another
Description
Hi, I was thinking whether it makes sense to add a boolean shouldFilter(HttpServletRequest request) method in OncePerRequestFilter.
Why
Today, shouldNotFilter can be used to block filtering on specific requests.
The introduction of shouldFilter would enable for more intentional filtering.
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");
}
}Pseudo-implementation
protected boolean shouldFilter(HttpServletRequest request) throws ServletException {
return true;
}In the situation that a request is satisfied by both shouldNotFilter and shouldFilter, the shouldNotFilter will take precedence. Changes in the doFilter method would be:
- else {
+ else if (shouldFilter(httpRequest)) {
// Do invoke this filter...
request.setAttribute(alreadyFilteredAttributeName, Boolean.TRUE);Contributing
I am happy to take this on, provided the idea is accepted.
Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: supersededAn issue that has been superseded by anotherAn issue that has been superseded by another