ChuckerTeam / chucker

🔎 An HTTP inspector for Android & OkHTTP (like Charles but on device)
Apache License 2.0
3.96k stars 349 forks source link

[Feedback] Chucker usage with Ktor HTTP client #177

Closed psh closed 4 years ago

psh commented 4 years ago

I spent some time learning about the Ktor HTTP client recently, porting the HttpBinClient and HttpBinApi to the Ktor HTTP client as a learning exercise for myself.

In the process I was happy to find that Chucker works perfectly with the Ktor HTTP client when configured to use the OkHttp engine -

private val httpClient = HttpClient(OkHttp) {
    install(JsonFeature) {
        serializer = GsonSerializer()
    }
    engine {
        addInterceptor(chuckerInterceptor)
        addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
        config {
            followRedirects(true)
            readTimeout(30, TimeUnit.SECONDS)
            connectTimeout(30, TimeUnit.SECONDS)
            callTimeout(30, TimeUnit.SECONDS)
        }
    }
}

👍 Great work all!

cortinico commented 4 years ago

Awesome! Thanks for sharing this @psh!

GuilhE commented 3 years ago

Just to add my 2 cents, I've configured my HttpClient throughout expect/actual logic in a KMM project and Chucker runs happily on androidApp 😃