DevConsoleOkHttpInterceptor

class DevConsoleOkHttpInterceptor @JvmOverloads constructor(recorder: NetworkTransactionRecorder, timingsProvider: DevConsoleOkHttpEventListenerFactory? = null) : Interceptor

OkHttp application interceptor that only ever captures a bounded copy of request/response bodies and never lets a capture failure change what the host call sees. All capture errors are isolated from the host call; chain.proceed's result (success or thrown exception) is always exactly what reaches the caller.

A response with a declared Content-Length is captured eagerly via Response.peekBody before the host sees it. A response without one (chunked transfer and transparent-gzip responses, most commonly) whose content type is not known-binary and not text/event-stream is instead returned with its body wrapped in a bounded tee (TeeCapturingSource): bytes are copied as the host consumes them -- up to MAX_RESPONSE_PEEK_BYTES, pass-through-only past it -- and the transaction is recorded once the body reaches EOF or is closed, whichever comes first, with completedAt set to that moment. INVARIANT: every response chain.proceed returns is recorded. The tee upholds it for bodies that stay open past a short grace period -- a long-lived stream (NDJSON, long-poll) or a body the host never reads and never closes -- with a provisional metadata-only "streaming" record that the completion record later replaces in place; see DeferredResponseBodyCapture.

timingsProvider, when supplied, must be the same DevConsoleOkHttpEventListenerFactory instance installed as the client's eventListenerFactory -- see that class's kdoc for the wiring. Without it, every recorded transaction's DNS/TCP/TLS/wait/download phases are left null, same as today.

Constructors

Link copied to clipboard
constructor(recorder: NetworkTransactionRecorder, timingsProvider: DevConsoleOkHttpEventListenerFactory? = null)

Functions

Link copied to clipboard
open override fun intercept(chain: Interceptor.Chain): Response