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
Use this property to enable relative redirects as explained in and also using the same response wrapper as
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 ignore forwarded headers
public void setRelativeRedirects(boolean relativeRedirects)
RelativeRedirectFilterdoes. Or if both filters are used, only one will wrap the response.
By default, if this property is set to false, in which case calls to
HttpServletResponse.sendRedirect(String) are overridden in order
to turn relative into absolute URLs since (which Servlet containers are
also required to do) also taking forwarded headers into consideration.
relativeRedirects- whether to use relative redirects
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, java.io.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.