Open mohan-palisetti opened 1 year ago
Personally, I should have removed them in 4.0. They are not well-tested and should be marked as deprecated. Can you say why you want to use them?
well, we have a WebClient with a custom configuration for mTLS and bunch of filters for adding tokens, identity propagation etc. I was hoping to use it as-is instead of unpacking the functionality into gateway.
Changing the below code in WebClientHttpRoutingFilter class
return headersSpec.exchangeToMono(Mono::just)
// .log("webClient route")
.flatMap(res -> {
ServerHttpResponse response = exchange.getResponse();
response.getHeaders().putAll(res.headers().asHttpHeaders());
response.setStatusCode(res.statusCode());
// Defer committing the response until all route filters have run
// Put client response as ServerWebExchange attribute and write
// response later NettyWriteResponseFilter
exchange.getAttributes().put(CLIENT_RESPONSE_ATTR, res);
return chain.filter(exchange);
});
as shown below seems to have done the trick.
return headersSpec.exchangeToMono (res -> {
ServerHttpResponse response = exchange.getResponse();
response.getHeaders().putAll(res.headers().asHttpHeaders());
response.setStatusCode(res.statusCode());
// Save response body as it is released to prevent memory & connection leaks
exchange.getAttributes().put(CLIENT_RESPONSE_ATTR, res.bodyToFlux(DataBuffer.class));
return chain.filter(exchange);
});
And of course corresponding changes in WebClientWriteResponseFilter to consume Flux
IMO, it may be useful to make Netty routing/response filter configurable so it can be swapped out with a custom WebClient filters.
Thanks
PRs welcome
@mohan-palisetti could you please provide the changes you made in WebClientWriteResponseFilter to consume Flux? Thanks!
Describe the bug Enabling WebClientHttpRoutingFilter & WebClientWriteResponseFilter leaves gateway client hanging. I can confirm that downstream HTTP calls works fine (200 OK with String Response), gateway logs also confirm 200 OK, but client is left hanging. Disabling WebClientHttpRoutingFilter & WebClientWriteResponseFilter beans (i.e., using default Netty routing & response handling) works just fine. We'd like to use a custom WebClient hence looking to get WebClientWriteResponseFilter working.
Appreciate any pointers. thanks
Sample