文章目录
- Spring Cloud Gateway 核心概念
- Spring Cloud Gateway 配置
- Spring Cloud Gateway 路由断言工厂
- GatewayFilter Factories 路由过滤器工厂
- AddReequestHeeader 过滤器工厂
- AddRequestParameter 过滤器工厂
- AddResponseHeader 过滤器工厂
- Hystrix 过滤器工厂
- FallbackHeaders 过滤器工厂
- PrefixPath 过滤器工厂
- PreserveHostHeader 过滤器工厂
- RequestRateLimiter 过滤器工厂
- 8.1. Redis RateLimiter
- RedirectTo 过滤器工厂
- RemoveNonProxyHeaders 过滤器工厂
- RemoveRequestHeader 过滤器工厂
- RemoveResponseHeader 过滤器工厂
- RewritePath 过滤器工厂
- RewriteResponseHeader 过滤器工厂
- SaveSession 过滤器工厂
- SaveSession 过滤器工厂
- SetPath 过滤器工厂
- SetResponseHeader 过滤器工厂
- SetStatus 过滤器工厂
- StripPrefix 过滤器工厂
- Retry 过滤器工厂
- RequestSize 过滤器工厂
- Modify Request Body 过滤器工厂
- Modify Response Body 过滤器工厂
-
Spring Cloud Gateway 核心概念
路由(route):路由网关的基本构建块。它由一个 ID、一个目的 URI、一组谓词和一组过滤器定义。如果聚合谓词为真,则路由匹配。
断言(predicate): java 8中的断言函数。Spring Cloud Gateway 中的断言函数输入类型是 Spring 5.0 框架中的 ServerWebExchange。Spring Cloud Gateway 中的断言函数允许开发者去定义匹配来自于 http request 中的任何信息,比如请求头和参数等
过滤器(filter):一个标准的Spring webFilter。Spring Cloud Gateway中的Filter分为两种类型的Filter,分别是Gateway Filter和Global Filter.网关 Filter实例是由Spring 框架中的网关Filter的特殊工厂构造。request在转发到目前服务之前,response在返回到调用端之前都可以被修改或者自定义。
-
Spring Cloud Gateway 配置
spring: cloud: gateway: discovery: locator: enabled: true lowerCaseServiceId: true logging: level: org.springframework.cloud.gateway: debug
enabled
:是否与服务发现组件进行结合,通过 serviceId 转发到具体的服务实例。默认为 false,若为 true 便开启基于服务发现的路由规则。
lowerCaseServiceId
:当注册中心为 Eureka 时,设置为 true 表示开启用小写的 serviceId 进行基于服务路由的转发。(Zookeeper、Consul 服务名默认小写) -
Spring Cloud Gateway 路由断言工厂
uri 可以lb://开头(lb代表从注册中心获取服务),后面接的就是你需要转发到的服务名称
-
After 路由断言工厂
After Route Predicate Factory 中会取一个 UTC 时间格式的时间参数,当请求进来的时间在配置的 UTC 时间之后,则会匹配成功。spring: cloud: gateway: routes: - id: after_route uri: http://example.org predicates: - After=2017-01-20T17:42:47.789-07:00[America/Denver] # 其中 - After 的时间可以用以下代码生成 # String time = ZonedDateTime.now().format(DateTimeFormatter.ISO_ZONED_DATE_TIME);
-
Before 路由断言工厂
Before Route Predicate Factory 中会取一个 UTC 时间格式的时间参数,当请求进来的时间在配置的 UTC 时间之前,则会匹配成功。spring: cloud: gateway: routes: - id: before_route uri: http://example.org predicates: - Before=2017-01-20T17:42:47.789-07:00[America/Denver]
-
Between 路由断言工厂
Between Route Predicate Factory 中会取一个 UTC 时间格式的时间参数,当请求进来的时间在配置的 UTC 时间之间,则会匹配成功。spring: cloud: gateway: routes: - id: between_route uri: http://example.org predicates: - Between=2017-01-20T17:42:47.789-07:00[America/Denver], 2017-01-21T17:42:47.789-07:00[America/Denver]
-
Cookie 路由断言工厂
Cookie Route Predicate Factory 中会取两个参数——cookie名称对应的 key 和 value。当请求中携带的 cookie 和 Cookied 断言工厂中配置的 cookie 一致,则路由匹配成功。
此路由匹配请求具有名为spring: cloud: gateway: routes: - id: cookie_route uri: http://example.org predicates: - Cookie=chocolate, ch.p
chocolate
,值与ch.p
正则表达式匹配的 cookie 。 -
Header 路由断言工厂
Header Route Predicate Factory 根据配置的 header 信息进行断言匹配路由,匹配成功进行转发。
如果请求具有名为spring: cloud: gateway: routes: - id: header_route uri: http://example.org predicates: - Header=X-Request-Id, \d+
X-Request-Idwhos
的标头值与\d+
正则表达式匹配(具有一个或多个数字的值),则此路由匹配。 -
Host 路由断言工厂
Host Route Predicate Factory 根据配置的 Host,对请求中的 Host 进行断言处理,断言成功进行转发。
如果请求的 Host 标头具有值spring: cloud: gateway: routes: - id: host_route uri: http://example.org predicates: - Host=**.somehost.org,**.anotherhost.org # 也支持 URI 模板变量,例如 {sub}.myhost.org。 # 此谓词将 URI 模板变量(sub 如上例中定义的)提取为名称和值的映射,并将其放在 ServerWebExchange.getAttributes() 带有定义的键的位置 ServerWebExchangeUtils.URI_TEMPLATE_VARIABLES_ATTRIBUTE。然后,这些值可供 GatewayFilter Factories 使用
www.somehost.org
或beta.somehost.org
或www.anotherhost.org
,则此路由将匹配。 -
Method 路由断言工厂
Method Route Predicate Factory 接受一个参数:HTTP方法来匹配。spring: cloud: gateway: routes: - id: method_route uri: http://example.org predicates: - Method=GET
-
Path 路由断言工厂
Path Route Predicate Factory 接受一个参数:采用Spring PathMatcher 模式。
如果请求路径是spring: cloud: gateway: routes: - id: method_route uri: http://example.org predicates: - Path=/foo/{segment},/bar/{segment} # 或者可以使用 /foo/**,匹配以 foo 为前缀的路径 # 此谓词将 URI 模板变量(segment 如上例中定义的)提取为名称和值的映射,并将其放在 ServerWebExchange.getAttributes() 带有定义的键的位置 ServerWebExchangeUtils.URI_TEMPLATE_VARIABLES_ATTRIBUTE。然后,这些值可供 GatewayFilter Factories 使用。 # 可以使用实用程序方法来更轻松地访问这些变量。 Map<String, String> uriVariables = ServerWebExchangeUtils.getPathPredicateVariables(exchange); String segment = uriVariables.get("segment");
/foo/1
或/foo/bar
或/bar/baz
,则此路由将匹配。 -
Query 路由断言工厂
Query Route Predicate Factory 接受两个参数:一个必需的参数(param)和一个可选的表达式(regexp)。
匹配请求包含spring: cloud: gateway: routes: - id: query_route uri: http://example.org predicates: - Query=foo, ba. # 或者 - Query=foo 匹配如果请求包含一个 foo 查询参数。
foo
其值与ba.regexp
匹配的查询参数 -
RemoteAddr 路由断言工厂
RemoteAddr Route Predicate Factory 配置一个 IPv4 或 IPv6 网段的字符串或者 IP,当请求 IP 地址在网段之内或者和配置的 IP 相同,则表示匹配成功进行转发。192.168.0.1/16
(其中192.168.0.1
是 IP 地址并且 16 是子网掩码)。
如果请求的远程地址是spring: cloud: gateway: routes: - id: method_route uri: http://example.org predicates: - RemoteAddr=192.168.1.1/24
192.168.1.10
,则此路由将匹配。 -
Weight 路由断言工厂
Weight Route Predicate Factory 才用分组的方式来实现权重路由。spring: cloud: gateway: routes: - id: service_v1 uri: http://localhost:8081/v1 predicates: - Path=/test - Weight=service1, 95 - id: service_v2 uri: http://localhost:8081/v2 predicates: - Path=/test - Weight=service1, 5
Weight=service1, 95
和Weight=service1, 5
就是路由的权重信息。
-
-
GatewayFilter Factories 路由过滤器工厂
过滤器允许以某种方式修改传入的HTTP请求或返回的HTTP响应。过滤器的作用域是某些特定路由。Spring Cloud Gateway包括许多内置的 Filter工厂。
-
AddReequestHeeader 过滤器工厂
AddRequestHeader 过滤器工厂用于对匹配上的请求加上 header。
spring: cloud: gateway: routes: - id: add_request_header_route uri: http://example.org filters: - AddRequestHeader = X-Request-Foo , Bar
-
AddRequestParameter 过滤器工厂
AddRequestParameter 过滤器工厂用于对匹配上的请求加上请求参数。
spring: cloud: gateway: routes: - id: add_request_parameter_route uri: http://example.org filters: - AddRequestParameter=foo, bar
-
AddResponseHeader 过滤器工厂
AddResponseHeader 过滤器工厂对从网关返回的响应添加 Header。
spring: cloud: gateway: routes: - id: add_request_header_route uri: http://example.org filters: - AddResponseHeader = X-Response-Foo , Bar
-
Hystrix 过滤器工厂
Hystrix 是 Netflix 开源的断路器组件。Hystrix GatewayFilter 允许你向网关路由引入断路器,保护你的服务不受级联故障的影响,并允许你在下游故障时提供 fallback 响应。
要在项目中启用 Hystrix 网关过滤器,请从Spring Cloud Netflix添加依赖项 spring-cloud-starter-netflix-hystrix .
Hystrix GatewayFilter Factory 需要一个
name
参数,即HystrixCommand
的名称。这将剩余的过滤器包装在命令名为myCommandName
的HystrixCommand
中。spring: cloud: gateway: routes: - id: hystrix_route uri: http://example.org filters: - Hystrix=myCommandName
hystrix 过滤器还可以接受可选的
fallbackUri
参数。目前,仅支持forward:
预设的 URI,如果调用 fallback,则请求将转发到与 URI 匹配的控制器。
访问/consumingserviceendpoint
降级后直接 fallback 到配置的 fallbackUrispring: cloud: gateway: routes: - id: hystrix_route uri: lb://backing-service:8088 predicates: - Path=/consumingserviceendpoint filters: - name: Hystrix # Hystrix Filter 的名称 args: # Hystrix 配置参数 name: fallbackcmd # HystrixCommand 的名字 fallbackUri: forward:/incaseoffailureusethis # fallback 对应的 uri - RewritePath = / consumeserviceendpoint , / backingserviceendpoint # Hystrix 的 fallbackcmd 的时间 hystrix.command.fallbackcmd.execution.isolation.thread.timeoutInMilliseconds: 5000
-
FallbackHeaders 过滤器工厂
FallbackHeaders 过滤器工厂允许在转发到外部应用程序中的 FallbackUri 的请求的 header 中添加 Hystrix 异常详细信息。
spring: cloud: gateway: routes: - id: ingredients uri: lb://ingredients predicates: - Path=//ingredients/** filters: - name: Hystrix args: name: fetchIngredients fallbackUri: forward:/fallback - id: ingredients-fallback uri: http://localhost:9994 predicates: - Path=/fallback filters: - name: FallbackHeaders args: executionExceptionTypeHeaderName: Test-Header
在运行
HystrixCommand
发生执行异常后,请求将被转发到localhost:9994
应用程序中的 fallback 终端或程序。异常类型、消息(如果可用)cause exception
类型和消息的头,将由 FallbackHeaders filter 添加到该请求中。通过设置下面列出的参数值及其默认值,可以在配置中覆盖headers的名称:
executionExceptionTypeHeaderName ("Execution-Exception-Type")
executionExceptionMessageHeaderName ("Execution-Exception-Message")
rootCauseExceptionTypeHeaderName ("Root-Cause-Exception-Type")
rootCauseExceptionMessageHeaderName ("Root-Cause-Exception-Message")
Hystrix 如何实现的更多细节可以参考 Hystrix GatewayFilter Factory section.
-
PrefixPath 过滤器工厂
PrefixPath 过滤器工厂只有一个
prefix
参数。spring: cloud: gateway: routes: - id: prefixpath_route uri: http://example.org filters: - PrefixPath=/mypath
这将给所有匹配请求的路径加前缀
/mypath
。因此,向/hello
发送的请求将发送到/mypath/hello
。 -
PreserveHostHeader 过滤器工厂
PreserveHostHeader 过滤器工厂没有参数。设置了该 Filter 后,GatewayFilter 将不使用由 HTTP 客户端确定的
host header
,而是发送原始host header
。spring: cloud: gateway: routes: - id: preserve_host_route uri: http://example.org filters: - PreserveHostHeader
-
RequestRateLimiter 过滤器工厂
RequestRateLimiter 过滤器工厂使用
RateLimiter
实现是否允许继续执行当前请求。如果不允许继续执行,则返回HTTP 429 - Too Many Requests
(默认情况下)。
这个过滤器可以配置一个可选的keyResolver
参数和rate limiter
参数(见下文)。
keyResolver
是KeyResolver
接口的实现类.在配置中,按名称使用 SpEL 引用 bean。#{@myKeyResolver}
是引用名为myKeyResolver
的 bean 的 SpEL 表达式。public interface KeyResolver { Mono<String> resolve(ServerWebExchange exchange); }
KeyResolver
接口允许使用可插拔策略来派生限制请求的 key。在未来的里程碑版本中,将有一些KeyResolver
实现。
KeyResolver
的默认实现是PrincipalNameKeyResolver
,它从ServerWebExchange
检索Principal
并调用Principal.getName()
。
默认情况下,如果KeyResolver
没有获取到 key,请求将被拒绝。此行为可以使用spring.cloud.gateway.filter.request-rate-limiter.deny-empty-key (true or false)
和spring.cloud.gateway.filter.request-rate-limiter.empty-key-status-code
属性进行调整。说明
无法通过"shortcut" 配置RequestRateLimiter。以下示例无效# INVALID SHORTCUT CONFIGURATION spring.cloud.gateway.routes[0].filters[0]=RequestRateLimiter=2, 2, #{@userkeyresolver}
8.1. Redis RateLimiter
Redis 的实现基于 Stripe 实现。它需要使用
spring-boot-starter-data-redis-reactive
Spring Boot starter。
使用的算法是 Token Bucket Algorithm。
redis-rate-limiter.replenishRate
是你允许用户每秒执行多少请求,而丢弃任何请求。这是令牌桶的填充速率。
redis-rate-limiter.burstCapacity
是允许用户在一秒钟内执行的最大请求数。这是令牌桶可以保存的令牌数。将此值设置为零将阻止所有请求。
稳定速率是通过在replenishRate
和burstCapacity
中设置相同的值来实现的。可通过设置burstCapacity
高于replenishRate
来允许临时突发流浪。在这种情况下,限流器需要在两次突发之间留出一段时间(根据replenishRate
),因为连续两次突发将导致请求丢失 (HTTP 429 - Too Many Requests
).。spring: cloud: gateway: routes: - id: requestratelimiter_route uri: http://example.org filters: - name: RequestRateLimiter args: redis-rate-limiter.replenishRate: 10 redis-rate-limiter.burstCapacity: 20
@Bean KeyResolver userKeyResolver() { return exchange -> Mono.just(exchange.getRequest().getQueryParams().getFirst("user")); }
这定义了每个用户 10 个请求的限制。允许 20 个突发,但下一秒只有 10 个请求可用。KeyResolver 是一个简单的获取 user 请求参数的工具(注意:不建议用于生产)。
限流器也可以定义为RateLimiter
接口的实现 bean。在配置中,按名称使用 SpEL 引用 bean 。#{@myRateLimiter}
是引用名为myRateLimiter
的bean的SpEL表达式。spring: cloud: gateway: routes: - id: requestratelimiter_route uri: http://example.org filters: - name: RequestRateLimiter args: rate-limiter: "#{@myRateLimiter}" key-resolver: "#{@userKeyResolver}"
-
RedirectTo 过滤器工厂
RedirectTo 过滤器工厂有一个
status
和一个url
参数。status 是 300 类重定向 HTTP 代码,如 301。该 URL 应为有效的 URL,这将是Location
header 的值。spring: cloud: gateway: routes: - id: prefixpath_route uri: http://example.org filters: - RedirectTo=302, http://acme.org
这将发送一个 302 状态码和一个
Location:http://acme.org
header 来执行重定向。 -
RemoveNonProxyHeaders 过滤器工厂
RemoveNonProxyHeaders 过滤器工厂从转发请求中删除headers。删除的默认头列表来自 IETF.
The default removed headers are:
- Connection
- Keep-Alive
- Proxy-Authenticate
- Proxy-Authorization
- TE
- Trailer
- Transfer-Encoding
- Upgrade
要更改此设置,请将
spring.cloud.gateway.filter.remove-non-proxy-headers.headers
属性设置为要删除的 header 名称。 -
RemoveRequestHeader 过滤器工厂
RemoveRequestHeader 过滤器工厂有一个
name
参数,这是要删除的 header 的名称。spring: cloud: gateway: routes: - id: removerequestheader_route uri: http://example.org filters: - RemoveRequestHeader=X-Request-Foo
这将在
X-Request-Foo
header被发送到下游之前删除它。 -
RemoveResponseHeader 过滤器工厂
RemoveResponseHeader 过滤器工厂有一个
name
参数,这是要删除的 header 的名称。spring: cloud: gateway: routes: - id: removeresponseheader_route uri: http://example.org filters: - RemoveResponseHeader=X-Response-Foo
这将在返回到网关 client 之前从响应中删除
x-response-foo
头。 -
RewritePath 过滤器工厂
RewritePath 过滤器工厂包含一个
regexp
正则表达式参数和一个replacement
参数. 通过使用 Java 正则表达式灵活地重写请求路径。spring: cloud: gateway: routes: - id: rewritepath_route uri: http://example.org predicates: - Path=/foo/** filters: - RewritePath=/foo/(?<segment>.*), /$\{segment}
对于请求路径
/foo/bar
,将在发出下游请求之前将路径设置为/bar
。注意,由于 YAML 规范,请使用$\
替换$
。 -
RewriteResponseHeader 过滤器工厂
RewriteResponseHeader 过滤器工厂包含
name
,regexp
和replacement
参数.。通过使用 Java 正则表达式灵活地重写响应头的值。spring: cloud: gateway: routes: - id: rewriteresponseheader_route uri: http://example.org filters: - RewriteResponseHeader=X-Response-Foo, , password=[^&]+, password=***
对于一个
/42?user=ford&password=omg!what&flag=true
的 header 值,在做下游请求时将被设置为/42?user=ford&password=***&flag=true
,由于 YAML 规范,请使用$\
替换$
。 -
SaveSession 过滤器工厂
SaveSession 过滤器工厂将调用转发到下游之前强制执行
WebSession::save
操作。这在使用 Spring Session 之类时特别有用,需要确保会话状态在进行转发调用之前已保存。spring: cloud: gateway: routes: - id: save_session uri: http://example.org predicates: - Path=/foo/** filters: - SaveSession
如果你希望要将 Spring Security 与 Spring Session 集成,并确保安全详细信息已转发到远程的进程,这一点至关重要。
-
SaveSession 过滤器工厂
SaveSession 过滤器工厂将许多headers添加到reccomedation处的响应中,从 this blog post.
添加以下标题(使用默认值分配):X-Xss-Protection:1; mode=block
Strict-Transport-Security:max-age=631138519
X-Frame-Options:DENY
X-Content-Type-Options:nosniff
Referrer-Policy:no-referrer
Content-Security-Policy:default-src 'self' https:; font-src 'self' https: data:; img-src 'self' https: data:; object-src 'none'; script-src https:; style-src 'self' https: 'unsafe-inline'
X-Download-Options:noopen
X-Permitted-Cross-Domain-Policies:none
要更改默认值,请在
spring.cloud.gateway.filter.secure-headers
命名空间中设置相应的属性:
Property to change:xss-protection-header
strict-transport-security
frame-options
content-type-options
referrer-policy
content-security-policy
download-options
permitted-cross-domain-policies
-
SetPath 过滤器工厂
SetPath 过滤器工厂采用
template
路径参数。它提供了一种通过允许路径的模板化 segments 来操作请求路径的简单方法。使用 Spring Framework 中的 URI 模板,允许多个匹配 segments。spring: cloud: gateway: routes: - id: setpath_route uri: http://example.org predicates: - Path=/foo/{segment} filters: - SetPath=/{segment}
对于一个
/foo/bar
请求,在做下游请求前,路径将被设置为/bar
。 -
SetResponseHeader 过滤器工厂
SetResponseHeader 过滤器工厂包括
name
和value
参数.spring: cloud: gateway: routes: - id: setresponseheader_route uri: http://example.org filters: - SetResponseHeader=X-Response-Foo, Bar
此GatewayFilter使用给定的名称替换所有header,而不是添加。因此,如果下游服务器响应为
X-Response-Foo:1234
,则会将其替换为X-Response-Foo:Bar
,这是网关客户端将接收的内容。 -
SetStatus 过滤器工厂
SetStatus 过滤器工厂包括唯一的
status
参数.必须是一个可用的 SpringHttpStatus
。它可以是整数值404
或字符串枚举NOT_FOUND
。spring: cloud: gateway: routes: - id: setstatusstring_route uri: http://example.org filters: - SetStatus=BAD_REQUEST - id: setstatusint_route uri: http://example.org filters: - SetStatus=401
在这个例子中,HTTP返回码将设置为401。
-
StripPrefix 过滤器工厂
StripPrefix 过滤器工厂包括一个
parts
参数。parts
参数指示在将请求发送到下游之前,要从请求中去除的路径中的节数。spring: cloud: gateway: routes: - id: nameRoot uri: http://nameservice predicates: - Path=/name/** filters: - StripPrefix=2
当通过网关发出
/name/bar/foo
请求时,向nameservice
发出的请求将是http://nameservice/foo
。 -
Retry 过滤器工厂
Retry 过滤器工厂包括
retries
,statuses
,methods
和series
参数。retries
:应尝试的重试次数statuses
:应该重试的HTTP状态代码,用org.springframework.http.HttpStatus
标识methods
: 应该重试的HTTP方法,用org.springframework.http.HttpMethod
标识series
: 要重试的一系列状态码,用org.springframework.http.HttpStatus.Series
标识
spring: cloud: gateway: routes: - id: retry_test uri: http://localhost:8080/flakey predicates: - Host=*.retry.com filters: - name: Retry args: retries: 3 statuses: BAD_GATEWAY
注意
retry filter 不支持body请求的重试,如通过body的POST 或 PUT请求注意
在使用带有前缀为forward:
的retry filter
时,应仔细编写目标端点,以便在出现错误时不会执行任何可能导致将响应发送到客户端并提交的操作。例如,如果目标端点是带注解的 controller,则目标 controller 方法不应返回带有错误状态代码的ResponseEntity
。相反,它应该抛出一个Exception
,或者发出一个错误信号,例如通过Mono.error(ex)
返回值,重试过滤器可以配置为通过重试来处理。 -
RequestSize 过滤器工厂
RequestSize 过滤器工厂可以限制请求不到达下游服务。过滤器以
RequestSize
作为参数,这是定义请求的允许大小限制(以字节为单位)。spring: cloud: gateway: routes: - id: request_size_route uri: http://localhost:8080/upload predicates: - Path=/upload filters: - name: RequestSize args: maxSize: 5000000
当请求因大小而被拒绝时, RequestSize GatewayFilter Factory 将响应状态设置为
413 Payload Too Large
,并带有额外的 headererrorMessage
。下面是一个errorMessage
的例子。
errorMessage : Request size is larger than permissible limit. Request size is 6.0 MB where permissible limit is 5.0 MB
注意 如果未在路由定义中作为filter参数提供,则默认请求大小将设置为5 MB。
-
Modify Request Body 过滤器工厂
Modify Request Body 过滤器工厂被定义为beta版本,将来API可能会改变。
此过滤器可用于在请求主体被网关发送到下游之前对其进行修改。注意
只能使用Java DSL配置此过滤器@Bean public RouteLocator routes(RouteLocatorBuilder builder) { return builder.routes() .route("rewrite_request_obj", r -> r.host("*.rewriterequestobj.org") .filters(f -> f.prefixPath("/httpbin") .modifyRequestBody(String.class, Hello.class, MediaType.APPLICATION_JSON_VALUE, (exchange, s) -> return Mono.just(new Hello(s.toUpperCase())))).uri(uri)) .build(); } static class Hello { String message; public Hello() { } public Hello(String message) { this.message = message; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } }
-
Modify Response Body 过滤器工厂
Modify Response Body 过滤器工厂被定义为beta版本,将来API可能会改变。
此过滤器可用于在将响应正文发送回客户端之前对其进行修改。注意
只能使用Java DSL配置此过滤器@Bean public RouteLocator routes(RouteLocatorBuilder builder) { return builder.routes() .route("rewrite_response_upper", r -> r.host("*.rewriteresponseupper.org") .filters(f -> f.prefixPath("/httpbin") .modifyResponseBody(String.class, String.class, (exchange, s) -> Mono.just(s.toUpperCase()))).uri(uri) .build(); }
-