类 ForwardedHeaderUtils
java.lang.Object
cn.taketoday.web.util.ForwardedHeaderUtils
Utility class to assist with processing "Forwarded" and "X-Forwarded-*" headers.
Note: There are security considerations surrounding the use of forwarded headers. Those should not be used unless the application is behind a trusted proxy that inserts them and also explicitly removes any such headers coming from an external source.
In most cases, you should not use this class directly but rather rely on
ForwardedHeaderFilter for Web MVC or
ForwardedHeaderTransformer in
order to extract the information from the headers as early as possible and discard
such headers. Underlying servers such as Tomcat, Jetty, and Reactor Netty also
provide options to handle forwarded headers even earlier.
- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev, Harry Yang
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明private static voidadaptForwardedHost(UriComponentsBuilder uriComponentsBuilder, String rawValue) static UriComponentsBuilderadaptFromForwardedHeaders(URI uri, HttpHeaders headers) private static booleanisForwardedSslOn(HttpHeaders headers) static InetSocketAddressparseForwardedFor(URI uri, HttpHeaders headers, InetSocketAddress remoteAddress) Parse the first "Forwarded: for=..." or "X-Forwarded-For" header value to anInetSocketAddressrepresenting the address of the client.
-
字段详细资料
-
FORWARDED_VALUE
- 另请参阅:
-
FORWARDED_HOST_PATTERN
-
FORWARDED_PROTO_PATTERN
-
FORWARDED_FOR_PATTERN
-
-
构造器详细资料
-
ForwardedHeaderUtils
public ForwardedHeaderUtils()
-
-
方法详细资料
-
adaptFromForwardedHeaders
Adapt the scheme+host+port of the givenURIfrom the "Forwarded" header (see RFC 7239) or from the "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" headers if "Forwarded" is not present.- 参数:
uri- the requestURIheaders- the HTTP headers to consider- 返回:
- a
UriComponentsBuilderthat reflects the request URI and additional updates from forwarded headers
-
isForwardedSslOn
-
adaptForwardedHost
-
parseForwardedFor
@Nullable public static InetSocketAddress parseForwardedFor(URI uri, HttpHeaders headers, @Nullable InetSocketAddress remoteAddress) Parse the first "Forwarded: for=..." or "X-Forwarded-For" header value to anInetSocketAddressrepresenting the address of the client.- 参数:
uri- the requestURIheaders- the request headers that may contain forwarded headersremoteAddress- the current remote address- 返回:
- an
InetSocketAddresswith the extracted host and port, ornullif the headers are not present - 另请参阅:
-