PatPanda
PatPanda

Reputation: 5010

Webflux Webclient - Error when sending HTTP2 requests as client to a HTTP2 enabled server

Small question regarding an issue while sending HTTP2 request to a server that is HTTP2 enabled please

Caused by: io.netty.handler.codec.http2.Http2Exception: First received frame was not SETTINGS. Hex dump for first 5 bytes: 485454502f

The setup: On server side, a Spring Webflux application 2.4.2, where http2 with mTLS is enabled. The java version is 11. The netty version is 4.

server.http2.enabled=true
server.ssl.client-auth=need
server.ssl.enabled-protocols=TLSv1.3
server.ssl.enabled=true
server.ssl.key-alias=server
server.ssl.key-password=x
server.ssl.key-store-password=x
server.ssl.key-store-provider=SUN
server.ssl.key-store-type=JKS
server.ssl.key-store=keystore.p12
server.ssl.trust-store-password=x
server.ssl.trust-store-provider=SUN
server.ssl.trust-store-type=JKS
server.ssl.trust-store=truststore.p12

I know it is HTTP2 successfully enabled, because when I curl it, I see on the curl response.

* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* Connection state changed (MAX_CONCURRENT_STREAMS == 4294967295)!
< HTTP/2 200

And in server side log, I do see Feb/2021:+0000] "GET /route HTTP/2.0" 200 288448 24 ms

Now, the issue:

A client using Webflux Webclient, initialized as such:

WebClient.create().mutate().defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).clientConnector(new ReactorClientHttpConnector(HttpClient.create().protocol(HttpProtocol.H2).wiretap(true).secure(sslContextSpec -> sslContextSpec.sslContext(getSslContext())))).build();

Note the .protocol(HttpProtocol.H2)

When using this Webclient to send the exact same request to this http2 enabled server, I see this exception: First received frame was not SETTINGS. Hex dump for first 5 bytes: 485454502f;

org.springframework.web.reactive.function.client.WebClientRequestException: First received frame was not SETTINGS. Hex dump for first 5 bytes: 485454502f; nested exception is io.netty.handler.codec.http2.Http2Exception: First received frame was not SETTINGS. Hex dump for first 5 bytes: 485454502f
    at org.springframework.web.reactive.function.client.ExchangeFunctions$DefaultExchangeFunction.lambda$wrapException$9(ExchangeFunctions.java:137) ~[spring-webflux-5.3.3.jar!/:5.3.3]

After research online, 485454502f stands for HTTP/, but my server is HTTP2 enabled!

It is not a gRPC server, just HTTP2 enabled.

Hence, I do not understand why am I facing this issue.

Thank you for your help.

Upvotes: 0

Views: 1478

Answers (1)

PatPanda
PatPanda

Reputation: 5010

From Spring Team:

Reactor Netty provides two types of SslContext configuration:

https://projectreactor.io/docs/netty/release/api/reactor/netty/tcp/SslProvider.SslContextSpec.html

You can provide either SslContext or SslContextBuilder.

Solution:

Either extend SslContext with a configuration that supports HTTP/2 Or provide SslContextBuild and Reactor Netty will be able to apply some default HTTP/2 configuration

I tried, both worked (thanks to Spring team)

Upvotes: 0

Related Questions