core / pragma.http /

Package pragma.http #

Types #

NameSummary

Apache5HttpClientFactory

object Apache5HttpClientFactory

Builds outbound ktor clients on the Apache5 engine, which pools connections. CIO only reuses connections when pipelining is enabled, so every request would otherwise pay a new TCP connect and TLS handshake.

ClientCertificate

class ClientCertificate(keyStore: KeyStore, password: CharArray)

A client certificate the HTTP client presents for mutual TLS. Server trust stays the JVM default.

ConcurrencyLimitedHttpClient

class ConcurrencyLimitedHttpClient(delegate: TimedHttpClient, semaphore: MetrickingPragmaSemaphore) : HttpClient

Wraps a TimedHttpClient with a per-instance cap on the number of concurrent outbound requests, enforced by a MetrickingPragmaSemaphore. Each convenience method holds a permit for the duration of the call. use is a pass-through and is not permit-limited: it hands out the raw ktor client rather than issuing a single request.

HttpFailureReason

enum HttpFailureReason(tagValue: String) : Enum<HttpFailureReason>

Value of the failure_reason tag on outbound HTTP timers. NONE covers both success and an HTTP error status, which the result tag already records.

HttpRequest

data class HttpRequest(httpMethod: HttpMethod, uri: String, body: Any = EmptyContent, auth: HeaderAuthCredentialsProvider = EmptyAuthProvider, expectSuccess: Boolean, headers: Map<String, String> = mapOf(), parameters: Map<String, String> = mapOf(), tags: List<String>, compressBody: Boolean = false, sensitiveValues: Map<String, String> = mapOf())

An outbound HTTP request.

HttpRequestFailedException

class HttpRequestFailedException(failureReason: HttpFailureReason, method: HttpMethod, uri: String, cause: Throwable) : RuntimeException

The one exception TimedHttpClient throws when a request fails without a response. failureReason says why, and the underlying exception is attached as the cause, a RedactedException copy is returned if the request contains any HttpRequest.sensitiveValues.

RedactedChainTruncatedException

class RedactedChainTruncatedException(maxDepth: Int) : RuntimeException

Marks where a redacted copy of a cause chain stops. The original’s deeper causes and suppressed throwables were dropped.

RedactedException

class RedactedException(originalClassName: String, redactedMessage: String?) : RuntimeException

Stands in for a throwable whose message carried a sensitive value. The cause is attached afterwards with initCause, so a cause chain that loops can be copied as the same loop.

SensitiveValues

class SensitiveValues(values: Map<String, String>)

Secrets an outbound request carries, keyed by a label. redact replaces each value, raw or URL-encoded, with <<label>>. Only declared values are matched, so a caller that sends a secret must declare it on the request.

TimedHttpClient

class TimedHttpClient(httpClient: HttpClient, timerName: String, timerProxyFactory: TimerProxyFactory) : HttpClient

Issues outbound requests and records their timing. The sensitiveValues parameter on each helper declares the secrets and provider account IDs the request carries, which are redacted from the exceptions thrown on failure. See HttpRequest.

Functions #

NameSummary

redacted

internal suspend fun ResponseException.redacted(sensitiveValues: SensitiveValues): ResponseException

Rebuilds ktor’s response exception, keeping its type, over a view of the response whose request URL is redacted. ktor builds the message from that URL, which is how query parameters reach logs. The view reads the original body unchanged. A subclass ktor does not define cannot be rebuilt with its own type, so it fails closed: it becomes a plain ResponseException, which callers catching that subclass by type no longer match.

internal fun Throwable.redacted(sensitiveValues: SensitiveValues): Throwable

Returns this throwable unchanged when no message in its cause or suppressed chain carries a sensitive value. Otherwise returns a copy of the chain made of RedactedExceptions.