Support returning OkHttpClient subclasses from OkHttpClient.Builder#build()
See original GitHub issueHello,
Here is a simplified view of my problem:
class MyOkHttpClient : OkHttpClient() {
// override something here
}
val client = MyOkHttpClient()
val newClient = client.newBuilder().build()
Given the above code, I would like newClient
to be an instance of MyOkHttpClient
.
My use case is: I’m trying to inspect websocket network traffic on Android. This isn’t supported by Android Profiler as far as I can tell, but it seems it should be possible with Stetho with a bit of work: http://zenandroid.io/monitoring-websockets-with-stetho/
However, I’m using OkHttp via Ktor. I can provide a preconfigued instance of OkHttpClient to Ktor, but the Ktor OkHttpEngine calls newBuilder().build()
and thus ends up using OkHttpClient, not MyOkHttpClient:
It would seem the purpose of declaring OkHttpClient to be open
is obviated somewhat by the fact that Builder#build() always returns OkHttpClient. Allowing users to override Builder#build() or pass a factory for creating instances of OkHttpClient would address this.
How do you feel about this?
Thanks
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Just to follow up, in case anyone has a similar use case, my pull request with Ktor was merged and it is now possible to pass a
WebSocket.Factory
to its configuration: https://github.com/ktorio/ktor/pull/2035Calling the Stetho method
NetworkEventReporter#webSocketFrameSent
depends on overriding OkHttp methodWebSocket#send()
. For example:Other reporting methods (
webSocketFrameReceived
, etc) depend on OkHttpWebSocketListener
.I have filed an issue with Ktor: https://youtrack.jetbrains.com/issue/KTOR-951