onResponseMetadata

fun HttpClientConfig<*>.onResponseMetadata(observer: (ResponseMetadata) -> Unit)

Observes HTTP status and response headers for every response received by this client, including error responses, retries, and redirects, before decoding or streaming the body. A transport failure or cancellation before receiving a response does not invoke observer.

The observer runs inline and should avoid blocking. Throwing from it fails the operation without retrying the request; coroutine cancellation remains cancellation. Concurrent requests may invoke the observer concurrently, so callers must coordinate any shared state.

Parameters

observer

receives a snapshot of each response's status and headers.