public class ForwardedHeaderFilter extends OncePerRequestFilter
sendRedirect(String). In effect the wrapped request and response reflect the client-originated protocol and address.
Note: This filter can also be used in a
removeOnly mode where "Forwarded" and "X-Forwarded-*"
headers are only eliminated without being used.
|Constructor and Description|
|Modifier and Type||Method and Description|
Same contract as for
Enables mode in which any "Forwarded" or "X-Forwarded-*" headers are removed only and the information in them ignored.
Can be overridden in subclasses for custom filtering control, returning
The dispatcher type
Whether to filter error dispatches such as when the servlet container processes and error mapped in
doFilter, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted
addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
public void setRemoveOnly(boolean removeOnly)
removeOnly- whether to discard and ingore forwarded headers
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException
trueto avoid filtering of the given request.
The default implementation always returns
protected boolean shouldNotFilterAsyncDispatch()
javax.servlet.DispatcherType.ASYNCintroduced in Servlet 3.0 means a filter can be invoked in more than one thread over the course of a single request. Some filters only need to filter the initial thread (e.g. request wrapping) while others may need to be invoked at least once in each additional thread for example for setting up thread locals or to perform final processing at the very end.
Note that although a filter can be mapped to handle specific dispatcher
web.xml or in Java through the
servlet containers may enforce different defaults with regards to
dispatcher types. This flag enforces the design intent of the filter.
The default return value is "true", which means the filter will not be invoked during subsequent async dispatches. If "false", the filter will be invoked during async dispatches with the same guarantees of being invoked only once during a request within a single thread.
protected boolean shouldNotFilterErrorDispatch()
web.xml. The default return value is "true", which means the filter will not be invoked in case of an error dispatch.
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException
doFilter, but guaranteed to be just invoked once per request within a single request thread. See
Provides HttpServletRequest and HttpServletResponse arguments instead of the default ServletRequest and ServletResponse ones.