Skip to content

Help users to register filters that require error or async dispatch with the correct dispatcher types #18953

@wilkinsona

Description

@wilkinsona

See spring-projects/spring-framework#23958 and #18931 for some background.

The servlet spec's default for a filter's dispatcher types is REQUEST. Boot's servlet component scanning and FilterRegistrationBean both align with this default. This creates a trap for users where they declare a filter that requires async dispatch, such as Framework's ShallowEtagHeaderFilter, and rely on the default dispatcher types as the filter won't work correctly as it will be unaware of the completion of the async processing.

Ideally, the servlet spec would allow a filter to detect such misconfiguration but it does not do so. spring-projects/spring-framework#23958 has updated Framework's docs to note the need to register both ShallowEtagHeaderFilter and ForwardedHeaderFilter for async dispatch. This issue is to explore if we can do something in Boot. A few possibilities:

  1. Automatically register for async dispatch any OncePerRequestFilter that returns false from shouldNotFilterAsyncDispatch().
  2. Log a warning if a OncePerRequestFilter that returns false from shouldNotFilterAsyncDispatcher() is not configured for async dispatch.
  3. Fail startup if a OncePerRequestFilter that returns false from shouldNotFilterAsyncDispatcher() is not configured for async dispatch.

These three possibilities all have their pros and cons and there may be other options too. Flagging for team attention to see what everyone thinks.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions