Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Use Chucker to Catch 'Em All

Use Chucker to Catch 'Em All

Do you know Chucker?

Chucker is an Open Source debugging tool for your Android apps that acts as an OkHttp interceptor. With Chucker, you can inspect and debug HTTP(S) requests and responses directly from your app, without the need of external desktop tools.

In this lightning talk, I will present Chucker 4.0, the latest stable release which comes packed with new feature such as GraphQL support, syntax highlighting, HAR support and much more.

It's time to stop using println to debug your network code, and start using Chucker to catch 'em all (your network requests)!

Nicola Corti

November 26, 2023
Tweet

More Decks by Nicola Corti

Other Decks in Programming

Transcript

  1. FEATURES API >= 21 OkHTTP 5 compatible no-op artifact persists

    network requests automically decode body export requests to file
  2. CONFIGURE CHUCKER public val chuckerInterceptor = ChuckerInterceptor.Builder(context) .maxContentLength(250_000L) .redactHeaders("Auth-Token", "Bearer")

    .alwaysReadResponseBody(true) .build() public val client = OkHttpClient.Builder() .addInterceptor(chuckerInterceptor) .build()
  3. CONFIGURE CHUCKER public val chuckerInterceptor = ChuckerInterceptor.Builder(context) .collector(chuckerCollector) .maxContentLength(250_000L) .redactHeaders("Auth-Token",

    "Bearer") .alwaysReadResponseBody(true) .build() public val client = OkHttpClient.Builder() .addInterceptor(chuckerInterceptor) .build()
  4. CONFIGURE CHUCKER public val chuckerCollector = ChuckerCollector( ) public val

    chuckerInterceptor = ChuckerInterceptor.Builder(context) .collector(chuckerCollector) .maxContentLength(250_000L) .redactHeaders("Auth-Token", "Bearer") .alwaysReadResponseBody(true) .build() public val client = OkHttpClient.Builder() .addInterceptor(chuckerInterceptor) .build()
  5. CONFIGURE CHUCKER public val chuckerCollector = ChuckerCollector( context = this,

    ) public val chuckerInterceptor = ChuckerInterceptor.Builder(context) .collector(chuckerCollector) .maxContentLength(250_000L) .redactHeaders("Auth-Token", "Bearer") .alwaysReadResponseBody(true) .build() public val client = OkHttpClient.Builder() .addInterceptor(chuckerInterceptor) .build()
  6. CONFIGURE CHUCKER public val chuckerCollector = ChuckerCollector( context = this,

    showNotification = true, ) public val chuckerInterceptor = ChuckerInterceptor.Builder(context) .collector(chuckerCollector) .maxContentLength(250_000L) .redactHeaders("Auth-Token", "Bearer") .alwaysReadResponseBody(true) .build() public val client = OkHttpClient.Builder() .addInterceptor(chuckerInterceptor) .build()
  7. CONFIGURE CHUCKER public val chuckerCollector = ChuckerCollector( context = this,

    showNotification = true, retentionPeriod = RetentionManager.Period.ONE_HOUR ) public val chuckerInterceptor = ChuckerInterceptor.Builder(context) .collector(chuckerCollector) .maxContentLength(250_000L) .redactHeaders("Auth-Token", "Bearer") .alwaysReadResponseBody(true) .build() public val client = OkHttpClient.Builder() .addInterceptor(chuckerInterceptor) .build()
  8. DECODING public object MyCustomDecoder : BodyDecoder { override fun decodeRequest(request:

    Request, body: ByteString): String? = if (shouldDecode()) { "¯\\_(ツ)_/¯" } else { null } } interceptorBuilder.addBodyDecoder(MyCustomDecoder).build() gzip brotli custom
  9. DECODING public object MyCustomDecoder : BodyDecoder { override fun decodeRequest(request:

    Request, body: ByteString): String? = if (shouldDecode()) { "¯\\_(ツ)_/¯" } else { null } override fun decodeResponse(request: Response, body: ByteString): String? = if (shouldDecode()) { "(┛◉Д◉)┛ 彡 ┻━┻" } else { null } } interceptorBuilder.addBodyDecoder(MyCustomDecoder).build() gzip brotli custom