NetworkCaptureSink
HTTP-client-agnostic sink that records network transactions.
The OkHttp adapter lives in :lustro; this SPI lets any HTTP client report the lifecycle of a request: beginRequest on dispatch, then one or more completeRequest calls (progressive for event streams) or a single failRequest. A request that a mock rule failed reports the rule with it.
The built-in sink returns from each call right away and records the transaction on a background thread once it's redacted, so a transaction can take a moment to show up.
Functions
Records the start of a request to url with the given method, headers, optional requestBody, and contentType, returning a TransactionId to correlate completion calls. The requestBody carries the captured text plus its truncation flag and full byte size.
Records the response to the transaction id. A request whose body the adapter captures whole reports one complete response. One whose body the app reads after that, such as a download or an event stream, reports an in-flight one when its headers arrive, and more as it reads if the adapter has progress to show, then a complete one when the app reaches the end of the body or closes it (see CapturedResponse.isComplete).
Records a failed transaction id after durationMs, with the error description. After a response was reported, it records that the body failed while the app read it, and the response's status and headers are kept.
Records the transaction id as failed after durationMs, with the error description, because the mock rule mockedBy failed it: a rule with a MockRule.failure, as returned by findMockRule. The Network tab then says which rule failed the request, as CapturedResponse.Builder.mockedBy does for a rule that answered one.