square / okhttp

Square’s meticulous HTTP client for the JVM, Android, and GraalVM.

Home Page:https://square.github.io/okhttp/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HttpClientSingleton.getHttpClient() can't add interceptor or modify connectTimeoutMillis

sayseakleng opened this issue · comments

Hello team! I have a challenge to add interceptor or modify connectTimeoutMillis with HttpClientSingleton.getHttpClient()
Since it is immutable, but there is a way change when application start or through jvm?

But with the alternative way to initiate http client, I can:
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.interceptors().add(new Interceptor())
httpClient.connectTimeout(aaa);

PS: there are some libraries use HttpClientSingleton.getHttpClient(), and I can't modify it.

Please use a site like stackoverflow for usage questions.

Generally the client is immutable, so if you can provide it, or override it with client.newBuilder().build() then you are out of luck.

For the connect timeout you can set it in an interceptor https://stackoverflow.com/a/49378091/1542667, but this requires you can set the interceptor.