如何使用代码配置Spring Cloud Gateway支持的类似SecureHeaders的GatewayFilter。

huangapple go评论75阅读模式
英文:

How use code to configure Spring cloud gateway supported GatewayFilter like SecureHeaders

问题

Spring Cloud Gateway有许多GatewayFilters,比如AddRequestHeader、SecureHeaders,在配置文件(比如application.yaml)中使用很方便,但如何在Java代码中使用这些GatewayFilters呢?

以下是你当前使用的配置代码:

route("route-1", predicateSpec -> predicateSpec.path("/api/**")
            .uri("http://localhost:5230")
            .filter(new SecureHeadersGatewayFilterFactory(new SecureHeadersProperties()).apply(new Object())))

是否有更好的解决方案呢?

英文:

Spring cloud gateway has many GatewayFilters like AddRequestHeader、SecureHeaders,use configure file like application.yaml is easy to use,but how use this GatewayFilters in java code?

spring:
  cloud:
    gateway:
      routes:
        - id: route-1
          uri: http://localhost1:5230
          predicates:
            - Path=/api/**
          filters:
            - SecureHeaders

Current I use the follow code to configure

route("route-1", predicateSpec -> predicateSpec.path("/api/**")
                .uri("http://localhost:5230")
                .filter(new SecureHeadersGatewayFilterFactory(new SecureHeadersProperties()).apply(new Object())))

Has more better solution?

答案1

得分: 1

route("route-1", predicateSpec -> predicateSpec.path("/api/**")
.filters(f -> f.secureHeaders()).uri("http://localhost:5230")

英文:
route("route-1", predicateSpec -> predicateSpec.path("/api/**")
                .filters(f -> f.secureHeaders()).uri("http://localhost:5230")

huangapple
  • 本文由 发表于 2020年9月28日 20:57:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/64102659.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定