当标头为 0时, WebFilterdoOnSuccessOrError
和doAfterSuccessOrError
消费者不工作。Content-Length
我有一个 WebFilter 如下:
@Bean
WebFilter webFilter() {
return (exchange, chain) ->
chain.filter(exchange)
.doOnRequest(value -> {
logger.error("webFilter" + " doOnRequest");
})
.doOnSuccessOrError((aVoid, throwable) -> {
logger.error("webFilter" + " doOnSuccessOrError");
})
.doAfterSuccessOrError((aVoid, throwable) -> {
logger.error("webFilter" + " doAfterSuccessOrError");
});
}
网关使用此配置将所有流量路由到 tomcat 应用程序:
@Bean
public RouteLocator routeLocator(RouteLocatorBuilder builder) {
return builder.routes()
.route(r -> r.path("/**")
.uri("http://localhost:9001").filter(gatewayFilter()))
.build();
}
我在 Spring Boot Tomcat 应用程序上有这三个端点:
@GetMapping("/redirect")
public ModelAndView redirectWithUsingRedirectPrefix(ModelMap model) {
return new ModelAndView("redirect:http://google.com", model);
}
@GetMapping("/empty-response")
public ResponseEntity<Void> responseEntity() {
return ResponseEntity.ok().build();
}
@GetMapping("/foo")
public ResponseEntity<String> string() {
return ResponseEntity.ok("foo");
}
通过网关请求/foo
它按预期工作
[ctor-http-nio-2] GatewayConfiguration : webFilter doOnRequest
[ctor-http-nio-2] GatewayConfiguration : globalFilter doOnRequest
[ctor-http-nio-3] GatewayConfiguration : gatewayFilter doOnRequest
[ctor-http-nio-3] GatewayConfiguration : gatewayFilter doOnSuccessOrError
[ctor-http-nio-3] GatewayConfiguration : globalFilter doOnSuccessOrError
[ctor-http-nio-3] GatewayConfiguration : globalFilter doAfterSuccessOrError
[ctor-http-nio-3] GatewayConfiguration : gatewayFilter doAfterSuccessOrError
[ctor-http-nio-2] GatewayConfiguration : webFilter doOnSuccessOrError
[ctor-http-nio-2] GatewayConfiguration : webFilter doAfterSuccessOrError
为了/empty-response
[ctor-http-nio-4] GatewayConfiguration : webFilter doOnRequest
[ctor-http-nio-4] GatewayConfiguration : globalFilter doOnRequest
[ctor-http-nio-3] GatewayConfiguration : gatewayFilter doOnRequest
[ctor-http-nio-3] GatewayConfiguration : gatewayFilter doOnSuccessOrError
[ctor-http-nio-3] GatewayConfiguration : globalFilter doOnSuccessOrError
[ctor-http-nio-3] GatewayConfiguration : globalFilter doAfterSuccessOrError
[ctor-http-nio-3] GatewayConfiguration : gatewayFilter doAfterSuccessOrError
GlobalFilter
并按GatewayFilter
预期工作。但是,如您所见,webFilter doOnSuccessOrError
并且webFilter doAfterSuccessOrError
缺少/empty-response
. /redirect
端点也是如此。