Class ForwardedRequestHeadersFilter

java.lang.Object
org.springframework.cloud.gateway.server.mvc.filter.ForwardedRequestHeadersFilter
All Implemented Interfaces:
BiFunction<org.springframework.http.HttpHeaders,org.springframework.web.servlet.function.ServerRequest,org.springframework.http.HttpHeaders>, HttpHeadersFilter<org.springframework.web.servlet.function.ServerRequest>, HttpHeadersFilter.RequestHttpHeadersFilter, org.springframework.core.Ordered

public class ForwardedRequestHeadersFilter extends Object implements HttpHeadersFilter.RequestHttpHeadersFilter, org.springframework.core.Ordered
Filter that creates RFC 7239 compliant Forwarded headers to send to downstream services.

This filter adds Forwarded headers containing information about the original request, including the client address (for), request protocol (proto), host header (host), and optionally the proxy interface that received the request (by).

The filter validates that proxies are trusted using a regular expression pattern configured via spring.cloud.gateway.server.webmvc.trusted-proxies.

Author:
raccoonback
See Also:
  • Field Details

  • Constructor Details

    • ForwardedRequestHeadersFilter

      @Deprecated public ForwardedRequestHeadersFilter()
      Deprecated.
    • ForwardedRequestHeadersFilter

      public ForwardedRequestHeadersFilter(String trustedProxiesRegex)
      Creates a new ForwardedRequestHeadersFilter with the specified trusted proxies pattern.
      Parameters:
      trustedProxiesRegex - regular expression pattern to match trusted proxy addresses
    • ForwardedRequestHeadersFilter

      public ForwardedRequestHeadersFilter(String trustedProxiesRegex, boolean forwardedByEnabled)
      Creates a new ForwardedRequestHeadersFilter with the specified trusted proxies pattern and forwarded-by enabled flag.
      Parameters:
      trustedProxiesRegex - regular expression pattern to match trusted proxy addresses
      forwardedByEnabled - whether to include the "by" parameter in the Forwarded header
  • Method Details

    • getOrder

      public int getOrder()
      Specified by:
      getOrder in interface org.springframework.core.Ordered
    • apply

      public org.springframework.http.HttpHeaders apply(org.springframework.http.HttpHeaders input, org.springframework.web.servlet.function.ServerRequest request)
      Specified by:
      apply in interface BiFunction<org.springframework.http.HttpHeaders,org.springframework.web.servlet.function.ServerRequest,org.springframework.http.HttpHeaders>