Skip to content

[Feature] Bring Ktor's CIO Engine Support to OkHttpProfiler #54

@sdfgsdfgd

Description

@sdfgsdfgd

We can port the OkHttpProfiler() to work with the default engine of ktor, not only CIO is the default engine nowadays but it's also the go-to for the multiplatform projects, OkHttpProfiler has been a favorite tool for many of us, let's continue the trend for at least another decade and this is the only future-proofing work that we need !

The Pain

  • CIO is Ktor’s default (pure coroutines, multiplatform), yet the profiler ignores it completely.
  • Swapping to the OkHttp engine just for debugging breaks parity in prod vs. dev and drags in extra deps.
  • External proxies (Charles, mitmproxy) work, but they’re outside Android Studio and lack the tight timing UI OkHttpProfiler gives.

What Needs to Happen

  1. Abstract the capture layer
    • Define an engine-agnostic interface for request/response events.
  2. Implement a CIO adapter
    • Hook Send and Receive pipeline phases.
    • Capture headers, body (with byte-limit), and timing.
  3. Reuse existing UI
    • Map new event model → current profiler panel without breaking existing OkHttp flow.
  4. Bonus
    • Expose a simple opt-in DSL:
      val client = HttpClient(CIO) {
          install(OkHttpProfilerCIO) {
              maxContentLength = 100_000
          }
      }

Why It’s Worth It

  • Major visibility bump — every default Ktor project instantly benefits.
  • Consistency — same profiler across Android, JVM, and KMP targets.
  • Community goodwill — avoids the “just switch engines, betch” answer that alienates devs.

Gotchas & Considerations

  • Coroutine context: ensure capture hooks don’t block or leak.
  • Binary size: keep the adapter lightweight to avoid bloating multiplatform artifacts.
  • Feature flags: default off, enabled explicitly to avoid surprise overhead.

Happy to spike a PR if maintainers bless the direction

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions