Tony Anecito
Tony Anecito

Reputation: 367

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

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

Upvotes: 10

Views: 3574

Answers (3)

Firzen
Firzen

Reputation: 2095

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

Upvotes: 1

Shubham Chaudhary
Shubham Chaudhary

Reputation: 50983

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

Upvotes: 6

Tony Anecito
Tony Anecito

Reputation: 367

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

Upvotes: 1

Related Questions