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

3.1k Views Asked by At

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

3

There are 3 best solutions below

1
On

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

1
On

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

0
On

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