类 ForwardedHeaderTransformer

java.lang.Object
cn.taketoday.http.server.reactive.ForwardedHeaderTransformer
所有已实现的接口:
Function<ServerHttpRequest,ServerHttpRequest>

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.

There are security considerations for forwarded headers since an application cannot know if the headers were added by a proxy, as intended, or by a malicious client. This is why a proxy at the boundary of trust should be configured to remove untrusted Forwarded headers that come from the outside.

You can also configure the ForwardedHeaderFilter with removeOnly, in which case it removes but does not use the headers.

从以下版本开始:
4.0 2022/10/21 12:19
作者:
Rossen Stoyanchev, Harry Yang
另请参阅:
  • 字段详细资料

    • FORWARDED_HEADER_NAMES

      static final Set<String> FORWARDED_HEADER_NAMES
    • removeOnly

      private boolean removeOnly
  • 构造器详细资料

    • ForwardedHeaderTransformer

      public ForwardedHeaderTransformer()
  • 方法详细资料

    • 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.
      参数:
      removeOnly - whether to discard and ignore forwarded headers
    • isRemoveOnly

      public boolean isRemoveOnly()
      Whether the "remove only" mode is on.
      另请参阅:
    • apply

      public ServerHttpRequest apply(ServerHttpRequest request)
      Apply and remove, or remove Forwarded type headers.
      指定者:
      apply 在接口中 Function<ServerHttpRequest,ServerHttpRequest>
      参数:
      request - the request
    • adaptFromForwardedHeaders

      private static URI adaptFromForwardedHeaders(URI uri, HttpHeaders headers)
    • hasForwardedHeaders

      protected boolean hasForwardedHeaders(ServerHttpRequest request)
      Whether the request has any Forwarded headers.
      参数:
      request - the request
    • removeForwardedHeaders

      private void removeForwardedHeaders(ServerHttpRequest.Builder builder)
    • getForwardedPrefix

      @Nullable private static String getForwardedPrefix(ServerHttpRequest request)