Package org.springframework.web.filter

# Class RelativeRedirectFilter

java.lang.Object
org.springframework.web.filter.GenericFilterBean
org.springframework.web.filter.OncePerRequestFilter
org.springframework.web.filter.RelativeRedirectFilter

All Implemented Interfaces:
  `Filter`, `org.springframework.beans.factory.Aware`, `org.springframework.beans.factory.BeanNameAware`, `org.springframework.beans.factory.DisposableBean`, `org.springframework.beans.factory.InitializingBean`, `org.springframework.context.EnvironmentAware`, `org.springframework.core.env.EnvironmentCapable`, `ServletContextAware`

public class RelativeRedirectFilter extends OncePerRequestFilter
Overrides `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.

Since:
  4.3.10
Author:
  Rob Winch, Rossen Stoyanchev

## Field Summary

### Fields inherited from class org.springframework.web.filter.OncePerRequestFilter

`ALREADY_FILTERED_SUFFIX`

### Fields inherited from class org.springframework.web.filter.GenericFilterBean

`logger`

## Constructor Summary

Constructors
Constructor
Description
`RelativeRedirectFilter()`

## Method Summary

Modifier and Type
Method
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.
`HttpStatusCode`
`getRedirectStatus()`
Return the configured redirect status.
`void`
`setRedirectStatus(HttpStatusCode status)`
Set the default HTTP Status to use for redirects.

### Methods inherited from class org.springframework.web.filter.OncePerRequestFilter

`doFilter, doFilterNestedErrorDispatch, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterAsyncDispatch, shouldNotFilterErrorDispatch`

### Methods inherited from class org.springframework.web.filter.GenericFilterBean

`addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### RelativeRedirectFilter

public RelativeRedirectFilter()

## Method Details

### setRedirectStatus

public void setRedirectStatus(HttpStatusCode status)
Set the default HTTP Status to use for redirects.

By default this is `HttpStatus.SEE_OTHER`.

Parameters:
  `status` - the 3xx redirect status to use

### getRedirectStatus

public HttpStatusCode getRedirectStatus()
Return the configured redirect status.

### doFilterInternal

protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException
Description copied from class: `OncePerRequestFilter`
Same contract as for `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.

Specified by:
  `doFilterInternal` in class `OncePerRequestFilter`
Throws:
  `ServletException`
  `IOException`