How to determine if Spring WebClient is using HTTP/2?
Spring WebClient uses ReactorClientHttpConnector
(A Reactor-Netty implementation of ClientHttpConnector
) by default. And according to this wiki Netty http-client does support HTTP/2 already.
If you want to check if your Spring WebClient is using HTTP/2 you can use tools like Wireshark to intercept your requests and analyse which protocol it is using.
Server Support for HTTP/2
As of Spring Framework 5.1 (Reactor Netty 0.8), this server supports as well HTTP/2. JDK9+ deployments will support that protocol without specific infrastructure changes.
Reactor is the underlying http client that is used by Spring WebClient. As of Spring Framework 5.1 this support HTTP/2.
See also Spring Framework: HTTP/2 support for an overview.
HTTP/2 is negotiated per connection
Wether your request connection is using HTTP/2 or HTTP/1.1 is negotiated per connection between client and server using ALPN. The server present what http versions it is supporting, then the client is choosing HTTP/2 if both parts support it. This is done over TLS in the handshake, so it can not be detected without terminating the TLS connection.
I've seen this answer on stackoverflow:
reactor.ipc.netty.channel.ChannelOperationsHandler does it for you. Just configure your logging system for that class to log at DEBUG level.
Where the output is something like:
2017-11-23 12:52:04.562 DEBUG 41449 --- [ctor-http-nio-5] r.i.n.channel.ChannelOperationsHandler : [id: 0x9183d6da, L:/127.0.0.1:57681 - R:localhost/127.0.0.1:8000] Writing object DefaultFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 0, cap: 0)) GET /api/v1/watch/namespaces/default/events HTTP/1.1
Perhaps I am wrong, but isn't HTTP/1.1 the output you would want? If so, check this thread:
how to log Spring 5 WebClient call