欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 养生 > Solon Cloud Gateway 开发:Route 的匹配检测器及定制

Solon Cloud Gateway 开发:Route 的匹配检测器及定制

2025/2/1 23:45:01 来源:https://blog.csdn.net/cwzb/article/details/145342281  浏览:    关键词:Solon Cloud Gateway 开发:Route 的匹配检测器及定制

RoutePredicateFactory 是一组专为路由匹配检测设计的接口,以完成匹配检测处理。对应 predicates 配置。

1、内置的匹配检测器

匹配检测器工厂本置前缀说明与示例
AfterPredicateFactoryAfter=After 时间检测器,ZonedDateTime 格式
(After=2017-01-20T17:42:47.789-07:00[America/Denver])
BeforePredicateFactoryBefore=After 时间检测器,ZonedDateTime 格式
(Before=2017-01-20T17:42:47.789-07:00[America/Denver])
CookiePredicateFactoryCookie=Cookie 检测器
(Cookie=token)(Cookie=token, ^user.)
HeaderPredicateFactoryHeader=Header 检测器
(Header=token)(Header=token, ^user.)
MethodPredicateFactoryMethod=Method 检测器
(Method=GET,POST)
PathPredicateFactoryPath=Path 检测器(支持多路径匹配,以","号隔开)
(Path=/demo/**) ,(Path=/demo/**,/hello/**)

2、定制示例

  • Path 检测器定制示例(配置例:Path=/demo/**
@Component
public class PathPredicateFactory implements RoutePredicateFactory {@Overridepublic String prefix() {return "Path";}@Overridepublic ExPredicate create(String config) {return new PathPredicate(config);}public static class PathPredicate implements ExPredicate {private PathRule rule;/*** @param config (Path=/demo/**)* */public PathPredicate(String config) {if (Utils.isBlank(config)) {throw new IllegalArgumentException("PathPredicate config cannot be blank");}rule = new PathRule();rule.include(config);}@Overridepublic boolean test(ExContext ctx) {return rule.test(ctx.rawPath());}}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com