英文:
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")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论