Class ForwardedHeaderTransformer
- java.lang.Object
- org.springframework.web.server.adapter.ForwardedHeaderTransformer
- All Implemented Interfaces:
Function<ServerHttpRequest,ServerHttpRequest>
- Direct Known Subclasses:
ForwardedHeaderFilter
public class ForwardedHeaderTransformer extends Object implements Function<ServerHttpRequest,ServerHttpRequest>
Extract values from "Forwarded" and "X-Forwarded-*" headers to override the request URI (i.e.HttpRequest.getURI()
) so it reflects the client-originated protocol and address.Alternatively if
removeOnly
is set to "true", then "Forwarded" and "X-Forwarded-*" headers are only removed, and not used.An instance of this class is typically declared as a bean with the name "forwardedHeaderTransformer" and detected by
WebHttpHandlerBuilder.applicationContext(ApplicationContext)
, or it can also be registered directly viaWebHttpHandlerBuilder.forwardedHeaderTransformer(ForwardedHeaderTransformer)
.- Since:
- 5.1
- Author:
- Rossen Stoyanchev
- See Also:
- https://tools.ietf.org/html/rfc7239
Constructor Summary
Constructors Constructor Description ForwardedHeaderTransformer()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ServerHttpRequest
apply(ServerHttpRequest request)
Apply and remove, or remove Forwarded type headers.protected boolean
hasForwardedHeaders(ServerHttpRequest request)
Whether the request has any Forwarded headers.boolean
isRemoveOnly()
Whether the "remove only" mode is on.void
setRemoveOnly(boolean removeOnly)
Enable mode in which any "Forwarded" or "X-Forwarded-*" headers are removed only and the information in them ignored.
Constructor Detail
ForwardedHeaderTransformer
public ForwardedHeaderTransformer()
Method Detail
setRemoveOnly
public void setRemoveOnly(boolean removeOnly)
Enable mode in which any "Forwarded" or "X-Forwarded-*" headers are removed only and the information in them ignored.- Parameters:
removeOnly
- whether to discard and ignore forwarded headers
isRemoveOnly
public boolean isRemoveOnly()
Whether the "remove only" mode is on.- See Also:
setRemoveOnly(boolean)
apply
public ServerHttpRequest apply(ServerHttpRequest request)
Apply and remove, or remove Forwarded type headers.- Specified by:
apply
in interfaceFunction<ServerHttpRequest,ServerHttpRequest>
- Parameters:
request
- the request
hasForwardedHeaders
protected boolean hasForwardedHeaders(ServerHttpRequest request)
Whether the request has any Forwarded headers.- Parameters:
request
- the request