Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

http2

okhttp

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

like image 741
Tony Anecito Avatar asked Jun 05 '15 07:06

Tony Anecito


People also ask

Does OkHttp support http2?

OkHttp (https://square.github.io/okhttp/) is an efficient HTTP & HTTP/2 client for Android and Java applications. It's been widely used in Android and has good documentation also.

Is OkHttp blocked?

OkHttp Overview At a high level, the client is designed for both blocking synchronous calls and nonblocking asynchronous calls. OkHttp supports Android 2.3 and above.

What is the underlying library of OkHttp?

Beginning with Mobile SDK 4.2, the Android REST request system uses OkHttp (v3. 2.0), an open-source external library from Square Open Source, as its underlying architecture. This library replaces the Google Volley library from past releases.

What is the use of OkHttp in Android?

OkHttp android provides an implementation of HttpURLConnection and Apache Client interfaces by working directly on a top of java Socket without using any extra dependencies.


2 Answers

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

like image 65
Shubham Chaudhary Avatar answered Oct 15 '22 13:10

Shubham Chaudhary


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

like image 30
Tony Anecito Avatar answered Oct 15 '22 13:10

Tony Anecito