类 ForwardedHeaderFilter
- 所有已实现的接口:
cn.taketoday.beans.factory.Aware,cn.taketoday.beans.factory.BeanNameAware,cn.taketoday.beans.factory.DisposableBean,cn.taketoday.beans.factory.InitializingBean,cn.taketoday.context.EnvironmentAware,cn.taketoday.core.env.EnvironmentCapable,ServletContextAware,Filter
There are security considerations for forwarded headers since an application cannot know if the headers were added by a proxy, as intended, or by a malicious client. This is why a proxy at the boundary of trust should be configured to remove untrusted Forwarded headers that come from the outside.
You can also configure the ForwardedHeaderFilter with removeOnly,
in which case it removes but does not use the headers.
- 从以下版本开始:
- 4.0 2022/3/27 22:00
- 作者:
- Rossen Stoyanchev, Eddú Meléndez, Rob Winch, Harry Yang
- 另请参阅:
-
嵌套类概要
嵌套类修饰符和类型类说明private static classExtract and use "Forwarded" or "X-Forwarded-*" headers.private static classprivate static classHide "Forwarded" or "X-Forwarded-*" headers.private static classResponsible for the contextPath, requestURI, and requestURL with forwarded headers in mind, and also taking into account changes to the path of the underlying delegate request (e.g. on a Servlet FORWARD). -
字段概要
字段修饰符和类型字段说明private booleanprivate boolean从类继承的字段 cn.taketoday.web.servlet.filter.OncePerRequestFilter
ALREADY_FILTERED_SUFFIX从类继承的字段 cn.taketoday.web.servlet.filter.GenericFilterBean
logger -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected voiddoFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) Same contract as fordoFilter, but guaranteed to be just invoked once per request within a single request thread.protected voiddoFilterNestedErrorDispatch(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) Typically an ERROR dispatch happens after the REQUEST dispatch completes, and the filter chain starts anew.voidsetRelativeRedirects(boolean relativeRedirects) Use this property to enable relative redirects as explained inRelativeRedirectFilter, and also using the same response wrapper as that filter does, or if both are configured, only one will wrap.voidsetRemoveOnly(boolean removeOnly) Enables mode in which any "Forwarded" or "X-Forwarded-*" headers are removed only and the information in them ignored.protected booleanshouldNotFilter(HttpServletRequest request) Can be overridden in subclasses for custom filtering control, returningtrueto avoid filtering of the given request.protected booleanThe dispatcher typejakarta.servlet.DispatcherType.ASYNCmeans a filter can be invoked in more than one thread over the course of a single request.protected booleanWhether to filter error dispatches such as when the servlet container processes and error mapped inweb.xml.从类继承的方法 cn.taketoday.web.servlet.filter.OncePerRequestFilter
doFilter, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted从类继承的方法 cn.taketoday.web.servlet.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
-
字段详细资料
-
FORWARDED_HEADER_NAMES
-
removeOnly
private boolean removeOnly -
relativeRedirects
private boolean relativeRedirects
-
-
构造器详细资料
-
ForwardedHeaderFilter
public ForwardedHeaderFilter()
-
-
方法详细资料
-
setRemoveOnly
public void setRemoveOnly(boolean removeOnly) Enables mode in which any "Forwarded" or "X-Forwarded-*" headers are removed only and the information in them ignored.- 参数:
removeOnly- whether to discard and ignore forwarded headers
-
setRelativeRedirects
public void setRelativeRedirects(boolean relativeRedirects) Use this property to enable relative redirects as explained inRelativeRedirectFilter, and also using the same response wrapper as that filter does, or if both are configured, only one will wrap.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, also taking into account forwarded headers.- 参数:
relativeRedirects- whether to use relative redirects
-
shouldNotFilter
从类复制的说明:OncePerRequestFilterCan be overridden in subclasses for custom filtering control, returningtrueto avoid filtering of the given request.The default implementation always returns
false.- 覆盖:
shouldNotFilter在类中OncePerRequestFilter- 参数:
request- current HTTP request- 返回:
- whether the given request should not be filtered
-
shouldNotFilterAsyncDispatch
protected boolean shouldNotFilterAsyncDispatch()从类复制的说明:OncePerRequestFilterThe dispatcher typejakarta.servlet.DispatcherType.ASYNCmeans 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 types via
web.xmlor in Java through theServletContext, servlet containers may enforce different defaults with respect 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.
-
shouldNotFilterErrorDispatch
protected boolean shouldNotFilterErrorDispatch()从类复制的说明:OncePerRequestFilterWhether to filter error dispatches such as when the servlet container processes and error mapped inweb.xml. The default return value is "true", which means the filter will not be invoked in case of an error dispatch. -
doFilterInternal
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException 从类复制的说明:OncePerRequestFilterSame contract as fordoFilter, but guaranteed to be just invoked once per request within a single request thread. SeeOncePerRequestFilter.shouldNotFilterAsyncDispatch()for details.Provides HttpServletRequest and HttpServletResponse arguments instead of the default ServletRequest and ServletResponse ones.
- 指定者:
doFilterInternal在类中OncePerRequestFilter- 抛出:
ServletExceptionIOException
-
doFilterNestedErrorDispatch
protected void doFilterNestedErrorDispatch(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException 从类复制的说明:OncePerRequestFilterTypically an ERROR dispatch happens after the REQUEST dispatch completes, and the filter chain starts anew. On some servers however the ERROR dispatch may be nested within the REQUEST dispatch, e.g. as a result of callingsendErroron the response. In that case we are still in the filter chain, on the same thread, but the request and response have been switched to the original, unwrapped ones.Sub-classes may use this method to filter such nested ERROR dispatches and re-apply wrapping on the request or response.
ThreadLocalcontext, if any, should still be active as we are still nested within the filter chain.
-