Set Up
- Client using Spring WebClient
- Reactor HttpClient protocols includes H2 (Reactor upgraded to 20.0.0)
- Server supports Http2
- TLS configured successfully
- Response payload is valid JSON
- Response headers from server uses compression
Actual Behavior
When the response from the server includes the Content-Encoding:gzip
the following error is observed.
java.util.concurrent.ExecutionException: org.springframework.core.codec.DecodingException: JSON decoding error: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\\r, \\n, \\t) is allowed between tokens; nested exception is com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\\r, \\n, \\t) is allowed between tokens\n at [Source: (io.netty.buffer.ByteBufInputStream); line: 1, column: 2]
Dependencies
- Spring Boot 2.3.5.RELEASE
- Reactor 20.0.0 (Upgraded in order to use Http2)
Configuration
Note : clientSslContextBuilder details excluded for brevity.
@Bean
public ReactorNettyHttpClientMapper reactorNettyHttpClientMapper(SslContextBuilder clientSslContextBuilder) {
return httpClient -> httpClient.secure(ssl -> ssl.sslContext(clientSslContextBuilder))
.protocol(HttpProtocol.H2);
}
@Bean
public WebClientCustomizer webClientCustomizer() {
return webClientBuilder -> webClientBuilder.baseUrl("https://localhost:8443/");
}
Usage
Note: WebClient.Builder injected from application context. Example abbreviated for brevity.
Mono<Dto> dto = webClientBuilder.get().uri("/").exchange().flatMap(r -> r.bodyToMono(Dto.class));
Service Details
-
Wiremock (gzip enabled) The issue was first observed when using the wiremock server. When the wiremock compression is disabled using
--disable-gzip
, the error described above is not observed. -
Spring Boot (embedded Tomcat) The issue was repeated using a simple Spring Boot server with the following properties set to enable compression for the response.
- server.compression.enabled=true
- server.compression.mime-types=application/json
- server.compression.min-response-size=1B
Notes
- If the Reactor HttpClient is configured to use Http1.1, the error does not occur.
Comment From: maddenj-ie
I've also tested this using Spring Boot 2.4.0-RC1 and observed the same behaviour. - Spring Framework 5.3.0 - Reactor 20.0.0
If you need any further information, please let me know. Regards.
Comment From: rstoyanchev
This is likely an issue for Reactor Netty. I don't see much that could explain it on the Spring Framework side. Can you try with just Reactor Netty HttpClient
. If it is still reproducible as I suspect it would be, then please re-open under https://github.com/reactor/reactor-netty.
Comment From: userquin
@rstoyanchev I have uploaded a simple project on #26018 for freemarker.
Comment From: violetagg
This seems to be Reactor Netty issue - please create an issue here https://github.com/reactor/reactor-netty/issues
Comment From: maddenj-ie
Hi @violetagg , Thanks for getting back to me. I've been unable to setup a Reactor Netty specific example so far. I've setup a sample app as per the Reactor documentation but it appears to hang. It may be related to the way I'm configuring my TLS but I'm unsure. Would it be sufficient to create the issue and just reference this one?
Comment From: violetagg
Would it be sufficient to create the issue and just reference this one?
@maddenj-ie Yes please do so