How It Works

  • 使用自定义处理器函数通过 HTTP 转发请求。

  • 提供附加的请求判断和过滤器函数实现。

  • 过滤器的顺序是 "before"、"请求处理器"、"after"、"响应处理器"。

  • 路由 URI 上定义的任何路径都将被忽略。

下图提供了 Spring Cloud Gateway 工作原理的高级概览:

spring cloud gateway mvc diagram

在 Spring Cloud Gateway Server MVC 中,路由是普通的 WebMvc.fn RouterFunction 实例,带有一个特殊的 HandlerFunction 来转发 org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions 中定义的 HTTP 上的请求。有关定期使用功能 API 的信息,请参见 WebMvc.fn 文档。

除了用于 HTTP 转发的自定义 HandlerFunctions 以外,Spring Cloud Gateway Server MVC 还提供 org.springframework.cloud.gateway.server.mvc.predicate.GatewayRequestPredicates 中的其他 RequestPredicate 实现以及 org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions 中的 HandlerFilterFunctions 实现。所有可以是纯“before”过滤器的自定义过滤器均在 org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions 中实现,并在 FilterFunctions 中调整为请求处理器。 org.springframework.cloud.gateway.server.mvc.filter.AfterFilterFunctions 中的自定义“after”过滤器也在 FilterFunctions 中调整为响应处理器。

还有用于可选过滤器的其他 *FilterFunctions 类,并将与每个过滤器一起记录在案。

将在路由 URI 上定义的任何路径忽略。