public class RelativeRedirectFilter extends OncePerRequestFilter
HttpServletResponse.sendRedirect(String)
and handles it by
setting the HTTP status and "Location" headers, which keeps the Servlet
container from re-writing relative redirect URLs into absolute ones.
Servlet containers are required to do that but against the recommendation of
RFC 7231 Section 7.1.2,
and furthermore not necessarily taking into account "X-Forwarded" headers.
Note: While relative redirects are recommended in the RFC, under some configurations with reverse proxies they may not work.
ALREADY_FILTERED_SUFFIX
logger
Constructor and Description |
---|
RelativeRedirectFilter() |
Modifier and Type | Method and Description |
---|---|
protected void |
doFilterInternal(HttpServletRequest request,
HttpServletResponse response,
FilterChain filterChain)
Same contract as for
doFilter , but guaranteed to be
just invoked once per request within a single request thread. |
HttpStatus |
getRedirectStatus()
Return the configured redirect status.
|
void |
setRedirectStatus(HttpStatus status)
Set the default HTTP Status to use for redirects.
|
doFilter, doFilterNestedErrorDispatch, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterAsyncDispatch, shouldNotFilterErrorDispatch
addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
public void setRedirectStatus(HttpStatus status)
By default this is HttpStatus.SEE_OTHER
.
status
- the 3xx redirect status to usepublic HttpStatus getRedirectStatus()
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException
OncePerRequestFilter
doFilter
, but guaranteed to be
just invoked once per request within a single request thread.
See OncePerRequestFilter.shouldNotFilterAsyncDispatch()
for details.
Provides HttpServletRequest and HttpServletResponse arguments instead of the default ServletRequest and ServletResponse ones.
doFilterInternal
in class OncePerRequestFilter
ServletException
IOException