Spring Weblux 2.5.1: Header issue content-type:"application/json,Accept,application/json",
I am currently the client, making HTTP calls to different servers in public internet.
I need to send some requests, get some responses. Everything should be in JSON format.
Hence, in my code, I do:
public Mono<SomeResponsePojo> sendHttpRequest(SomeRequestPojo someRequestPojo) {
final Map<String, String> headers = Map.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE, HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
final HttpClient httpClient = HttpClient.create().wiretap(CATEGORY, LogLevel.INFO, AdvancedByteBufFormat.TEXTUAL);
return WebClient.create("https://the-api.com").mutate().clientConnector(new ReactorClientHttpConnector(httpClient)).build().post().headers(httpHeaders -> httpHeaders.setAll(headers)).body(BodyInserters.fromValue(someRequestPojo)).retrieve().bodyToMono(SomeResponsePojo.class);
Unfortunately, I have repeated comments from the different servers (it is not only one observing that issue) the header on their end looks like this:
content-length:"250",
remoteip:"some ip",
user-agent:"ReactorNetty/1.0.7",
accept:"*/*",
content-type:"application/json,Accept,application/json",
I was expecting to see header with more of this format on the third party server side:
content-length:"250",
remoteip:"some ip",
user-agent:"ReactorNetty/1.0.7",
accept:"application/json",
content-type:"application/json",
May I know what is the issue please?
Thank you for your time.
Absolutely @violetagg, And thank you again for looking into this.
I can confirm with a mock server I created for myself, I am not observing this issue.
But this is strange, because several servers/destinations came to me saying they do see
content-type:"application/json,Accept,application/json",
And they have no idea of each other.
I suspected some kind of header manipulation on their end, because most of them are using Envoy, but it is hard to debug as they are third party APIs.
Finally, the last bit of clue I observe is this piece of log:
INFO [myservice,,] 10 --- [or-http-epoll-1] reactor.netty.http.client.HttpClient : [id:215c6cd6, L:/someip:someport - R:someipdestination/ip:port] USER_EVENT: SslHandshakeCompletionEvent(SUCCESS)
INFO [myservice,,] 10 --- [or-http-epoll-1] reactor.netty.http.client.HttpClient : [id:215c6cd6-1, L:/someip:someport - R:someipdestination/ip:port] WRITE: 326B POST /some/api HTTP/1.1
user-agent: ReactorNetty/1.0.7
host: destination.com
accept: */*
Content-Type: application/json
Content-Type: Accept
Content-Type: application/json
content-length: 250
INFO [myservice,,] 10 --- [or-http-epoll-1] reactor.netty.http.client.HttpClient : [id:215c6cd6-1, L:/someip:someport - R:someipdestination/ip:port] WRITE: 250B {my json payload}
INFO [myservice,,] 10 --- [or-http-epoll-1] reactor.netty.http.client.HttpClient : [id:215c6cd6-1, L:/someip:someport - R:someipdestination/ip:port] FLUSH
I then see the READ COMPLETE
and the response.
What is strange is this
accept: /
Content-Type: application/json
Content-Type: Accept
Content-Type: application/json
Still digging further, agree with you reproducing local seems fine, but the servers I am trying to call affirm this.
Hello @violetagg,
Indeed, I am not able to reproduce this.
The only thing I have are the .wiretap logs, which shows
user-agent: ReactorNetty/1.0.7
host: destination.com
accept: */*
Content-Type: application/json
Content-Type: Accept
Content-Type: application/json
content-length: 250
It is probably just me and my set.
Closing, and thanks