Package org.springframework.security.web.header.writers

# Class ReferrerPolicyHeaderWriter

java.lang.Object
org.springframework.security.web.header.writers.ReferrerPolicyHeaderWriter

All Implemented Interfaces:
  `HeaderWriter`

public class ReferrerPolicyHeaderWriter extends Object implements HeaderWriter

Provides support for Referrer Policy.

The list of policies defined can be found at Referrer Policies.

This implementation of `HeaderWriter` writes the following header:

- Referrer-Policy

By default, the Referrer-Policy header is not included in the response. Policy no-referrer is used by default if no `ReferrerPolicyHeaderWriter.ReferrerPolicy` is set.

Since:
  4.2

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static enum`
`ReferrerPolicyHeaderWriter.ReferrerPolicy`

## Constructor Summary

Constructors
Constructor
Description
`ReferrerPolicyHeaderWriter()`
Creates a new instance.
`ReferrerPolicyHeaderWriter(ReferrerPolicyHeaderWriter.ReferrerPolicy policy)`
Creates a new instance.

## Method Summary

Modifier and Type
Method
Description
`void`
`setPolicy(ReferrerPolicyHeaderWriter.ReferrerPolicy policy)`
Sets the policy to be used in the response header.
`void`
`writeHeaders(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)`
Create a `Header` instance.

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

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

## Constructor Details

### ReferrerPolicyHeaderWriter

public ReferrerPolicyHeaderWriter()
Creates a new instance. Default value: no-referrer.

### ReferrerPolicyHeaderWriter

public ReferrerPolicyHeaderWriter(ReferrerPolicyHeaderWriter.ReferrerPolicy policy)
Creates a new instance.

Parameters:
  `policy` - a referrer policy
Throws:
  `IllegalArgumentException` - if policy is null

## Method Details

### setPolicy

public void setPolicy(ReferrerPolicyHeaderWriter.ReferrerPolicy policy)
Sets the policy to be used in the response header.

Parameters:
  `policy` - a referrer policy
Throws:
  `IllegalArgumentException` - if policy is null

### writeHeaders

public void writeHeaders(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
Description copied from interface: `HeaderWriter`
Create a `Header` instance.

Specified by:
  `writeHeaders` in interface `HeaderWriter`
Parameters:
  `request` - the request
  `response` - the response
See Also:
  - `HeaderWriter.writeHeaders(HttpServletRequest, HttpServletResponse)`