跳到主要内容

网关处理程序过滤器函数

DeepSeek V3 中英对照 Gateway Handler Filter Functions

Before Filter 函数

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

筛选后函数

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

高级过滤函数

有些过滤器不能简单地归类为前置或后置过滤器。这些过滤器在代理请求之前和之后都会起作用。其中包括位于 BodyFilterFunctionsBucket4jFilterFunctionsCircuitBreakerFilterFunctionsLoadBalancerFilterFunctionsRetryFilterFunctionsTokenRelayFilterFunctions 中的过滤器,它们都位于 org.springframework.cloud.gateway.server.mvc.filter 包中。

章节总结