How do I verify okhttp is using http/2 for a request?
Asked Answered
L

3

10

How can I verify that okhttp negotiated http/2 successfully and did not use https/1.1 instead? Is there some info in the response I can check?

Thanks, -Tony

Leatherman answered 5/6, 2015 at 7:13 Comment(0)
D
6

FYI since okhttp 3.0 or so OkHttp-Selected-Protocol is not printed.

The protocol can be easily seen in the response object though.

Protocol in response

Deathbed answered 6/2, 2016 at 9:36 Comment(1)
Thanks, was quite helpful. Another option can be adding a custom network interceptor and log response.protocol() in it. square.github.io/okhttp/interceptorsLethalethal
L
1

Ok I think I got the answer. If I print out the response headers I got this: OkHttp-Selected-Protocol: h2

Am I to assume it negotiated successfully the response for http/2?

Thanks! -tony

Leatherman answered 5/6, 2015 at 7:29 Comment(1)
It's not printing such header in newer versions. You need to take the app in debug mode and track the response ->protocol -> nameBul
H
1

You can check protocol by calling:

Response response = client.newCall(request).execute();  // first get response from server
Protocol protocol = response.protocol();                // check which protocol was used
Hesperides answered 14/7, 2022 at 15:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.