-
Is it possible to modify the response body when using So far I have tried this in multiple ways and while I have managed to add headers to the response I have not figured out how to modify the response body. Any help would be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Here are some more details about this issue. The most "classic" way in this context do do response body manipulation, is to create public Publisher<MutableHttpResponse<?>> doFilter(HttpRequest<?> request, ServerFilterChain chain) {
return Publishers.map(client.proxy(
request.mutate() // (4)
.uri(b -> b ...
)
.header("X-My-Request-Header", "XXX") // (6)
), response -> response.header("X-My-Response-Header", "YYY")); The filter returns the proxy directly, instead of using the normal way of doing a filter, which is do return a This means that any subsequent filters are not run so they will not have any effect. I made multiple attempts to modify the returned publisher in this method in order to try to make the body available, but non worked. By hooking into the Netty client pipeline by using the methods described in the Logbook example in the docs (https://docs.micronaut.io/4.6.5/guide/#nettyClientPipeline) - It is possible to see that the ProxyHttpClient seems to do alot of chunking/buffering of the response, so you will only get the whole response if it is quite small, otherwise it is possible to get some parts of it. But so far I have not found any way to get the whole response, modify it, and then return it. Is this currently possible ? |
Beta Was this translation helpful? Give feedback.
ProxyHttpClient does not really expose the body. There will be an API that allows this in the near future using the new RawHttpClient API.