OkHttpSender

The default NetworkSender, backed by an OkHttp OkHttpClient.

The Network tab's Send form lists each sender by its name, and resolves a relative URL against its baseUrl. Register several with NetworkDebugTab.create(senders = ...), one for each client that the app builds with its own interceptors or for its own host:

NetworkDebugTab.create(
senders = listOf(
OkHttpSender.create("API (signed in)", baseUrl = "https://api.example.com") { apiClient },
OkHttpSender.create("CDN", baseUrl = "https://cdn.example.com") { cdnClient },
),
)

When the app can change its server at runtime, such as with a server picker in a debug menu, give the base URL as a function, which the tab calls for each send and each time it lists the senders:

OkHttpSender.create("API", baseUrlProvider = { serverSettings.currentBaseUrl }) { apiClient }

The runtime invokes send off the main thread and blocks for the result; this implementation issues a synchronous OkHttp call. A sent request appears as its own row in the traffic list only when the client carries the Lustro interceptor. Otherwise the Send form still reports the outcome (status, success), but the request is not captured.

At most 256 KB of the response body is read into NetworkSendResult.body. The response is then closed without reading the rest, so a large or endless response cannot exhaust the heap.

Constructors

Link copied to clipboard
constructor(client: OkHttpClient)

Creates a sender named "Default" that issues its calls through client. Its relative URLs resolve against DebugConfig.appServerBaseUrl when the tab gets it as senderClient.

Types

Link copied to clipboard
object Companion

Factories for OkHttpSender.

Properties

Link copied to clipboard

The URL that a relative URL in the Send form resolves against, or null when this sender takes absolute URLs only. For a sender created with a baseUrlProvider, each read calls the provider, so the value can change and the provider can throw.

Link copied to clipboard

The name that the Send form lists this sender under. Unique within a tab.

Functions

Link copied to clipboard
open override fun send(request: NetworkSendRequest): NetworkSendResult

Sends request synchronously and maps the outcome to a NetworkSendResult.