Gateway Handler Filter Functions

Before 过滤函数

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 更受青睐,因为它更明确。

After 过滤函数

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 更受青睐,因为它更明确。

高级过滤函数

有些过滤器不能简单地归类为 before 或 after 过滤器。这些过滤器在代理请求发生之前和之后都进行处理。其中一些过滤器包括位于 org.springframework.cloud.gateway.server.mvc.filter 包中的 BodyFilterFunctions, Bucket4jFilterFunctions, CircuitBreakerFilterFunctions, LoadBalancerFilterFunctions, RetryFilterFunctionsTokenRelayFilterFunctions 中的过滤器。