类 ForwardedHeaderFilter
- java.lang.Object
- org.springframework.web.filter.GenericFilterBean
- org.springframework.web.filter.OncePerRequestFilter
- org.springframework.web.filter.ForwardedHeaderFilter
- 所有已实现的接口:
Filter
,Aware
,BeanNameAware
,DisposableBean
,InitializingBean
,EnvironmentAware
,EnvironmentCapable
,ServletContextAware
public class ForwardedHeaderFilter extends OncePerRequestFilter
Extract values from "Forwarded" and "X-Forwarded-*" headers in order to wrap and override the following from the request and response:getServerName()
,getServerPort()
,getScheme()
,isSecure()
, andsendRedirect(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.- 从以下版本开始:
- 4.3
- 作者:
- Rossen Stoyanchev, Edd煤 Mel茅ndez, Rob Winch
- 另请参阅:
- https://tools.ietf.org/html/rfc7239
字段概要
从类继承的字段 org.springframework.web.filter.OncePerRequestFilter
ALREADY_FILTERED_SUFFIX
从类继承的字段 org.springframework.web.filter.GenericFilterBean
logger
构造器概要
构造器 构造器 说明 ForwardedHeaderFilter()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected void
doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
Same contract as fordoFilter
, but guaranteed to be just invoked once per request within a single request thread.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.void
setRemoveOnly(boolean removeOnly)
Enables mode in which any "Forwarded" or "X-Forwarded-*" headers are removed only and the information in them ignored.protected boolean
shouldNotFilter(HttpServletRequest request)
Can be overridden in subclasses for custom filtering control, returningtrue
to avoid filtering of the given request.protected boolean
shouldNotFilterAsyncDispatch()
The dispatcher typejavax.servlet.DispatcherType.ASYNC
introduced in Servlet 3.0 means a filter can be invoked in more than one thread over the course of a single request.protected boolean
shouldNotFilterErrorDispatch()
Whether to filter error dispatches such as when the servlet container processes and error mapped inweb.xml
.从类继承的方法 org.springframework.web.filter.OncePerRequestFilter
doFilter, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted
从类继承的方法 org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
构造器详细资料
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- 从以下版本开始:
- 4.3.9
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- 从以下版本开始:
- 4.3.10
shouldNotFilter
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException
从类复制的说明:OncePerRequestFilter
Can be overridden in subclasses for custom filtering control, returningtrue
to 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
- 抛出:
ServletException
- in case of errors
shouldNotFilterAsyncDispatch
protected boolean shouldNotFilterAsyncDispatch()
从类复制的说明:OncePerRequestFilter
The dispatcher typejavax.servlet.DispatcherType.ASYNC
introduced 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 types via
web.xml
or in Java through theServletContext
, 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.
shouldNotFilterErrorDispatch
protected boolean shouldNotFilterErrorDispatch()
从类复制的说明:OncePerRequestFilter
Whether 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
从类复制的说明:OncePerRequestFilter
Same 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.