How to determine if Spring WebClient is using HTTP/2?
Asked Answered
S

3

10

I would like to know whether Spring WebClient is using HTTP/2. How I can determine that?

Shipmaster answered 21/12, 2019 at 17:32 Comment(0)
G
6

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.

Gallagher answered 11/1, 2020 at 8:56 Comment(0)
H
7

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.

Hiss answered 9/1, 2020 at 13:13 Comment(1)
as @Jonas mentioned - HTTP2 is behind TLS so it is not possible to check without terminating TLS connection, so Wireshark only is not enoughShipmaster
G
6

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.

Gallagher answered 11/1, 2020 at 8:56 Comment(0)
C
2

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

Coltin answered 14/1, 2020 at 17:32 Comment(1)
afaik you are not able to see whether HTTP2 was used from http level - it's present on TCP/TLS levelShipmaster

© 2022 - 2024 — McMap. All rights reserved.