Gateway Handler Filter Functions

Before Filter Functions

WebMvc.fn API 具有“before”筛选器函数的概念,这是一个 java.util.Function<ServerRequest, ServerRequest>,该函数仅作用于请求。很多 before 筛选器函数在 org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions 中引用为静态工厂方法。它们在 org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions 中被调整为通用 org.springframework.web.servlet.function.HandlerFilterFunction<ServerResponse, ServerResponse>。两者都可以使用,但功能更具体的 BeforeFilterFunctions 优先使用(如有可能),因为它含义更明确。

The WebMvc.fn API has the concept of a "before" filter function, a java.util.Function<ServerRequest, ServerRequest> that only acts on the request. Many before filter functions are referenced in org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions as static factory methods. They are adapted to generic org.springframework.web.servlet.function.HandlerFilterFunction<ServerResponse, ServerResponse> in org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions. Either may be used, but the more specific BeforeFilterFunctions is preferred, where possible, as it is more explicit.

After Filter Functions

WebMvc.fn API 具有“after”筛选器函数的概念,这是一个 java.util.BiFunction<ServerRequest, ServerResponse, ServerResponse>,它可以修改响应。很多 after 筛选器函数在 org.springframework.cloud.gateway.server.mvc.filter.AfterFilterFunctions 中引用为静态工厂方法。它们在 org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions 中被调整为通用 org.springframework.web.servlet.function.HandlerFilterFunction<ServerResponse, ServerResponse>。两者都可以使用,但功能更具体的 AfterFilterFunctions 优先使用(如有可能),因为它含义更明确。

The WebMvc.fn API has the concept of a "after" filter function, a java.util.BiFunction<ServerRequest, ServerResponse, ServerResponse> that can modify the response. Many after filter functions are referenced in org.springframework.cloud.gateway.server.mvc.filter.AfterFilterFunctions as static factory methods. They are adapted to generic org.springframework.web.servlet.function.HandlerFilterFunction<ServerResponse, ServerResponse> in org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions. Either may be used, but the more specific AfterFilterFunctions is preferred, where possible, as it is more explicit.

Advanced Filter Functions

一些筛选器无法归类为简单的 before 或 after 筛选器。这些筛选器在代理请求发出前后都可以工作。部分筛选器包括 BodyFilterFunctionsBucket4jFilterFunctions、`CircuitBreakerFilterFunctionsLoadBalancerFilterFunctionsRetryFilterFunctionsTokenRelayFilterFunctions,这些筛选器全部位于 org.springframework.cloud.gateway.server.mvc.filter 包中。

Some filters can not be classified as a simple before or after filter. These filters do work both prior to and after the proxy request has been made. Some of these include filters located in BodyFilterFunctions, Bucket4jFilterFunctions, `CircuitBreakerFilterFunctions, LoadBalancerFilterFunctions, RetryFilterFunctions, and TokenRelayFilterFunctions, all located in the org.springframework.cloud.gateway.server.mvc.filter package.