scoop:scoop.http.client:0.1.0
src/config.scoop
Selected production source · src/config.scoop
1
package scoop.http.client3
import scoop.asyncio.tcpConnectOptions5
import scoop.asyncio.TcpConnectOptions6
import scoop.collections.emptyList7
import scoop.http.*8
import scoop.time.Duration9
import scoop.tls.*11
/**12
* Restricts the HTTP protocol versions the client may negotiate.13
*/14
public enum HttpVersionPolicy {15
/**16
* Negotiates HTTP/2 or HTTP/1.1 through TLS ALPN, with explicit cleartext policy.17
*/18
Auto,19
/**20
* Permits only HTTP/1 connections.21
*/22
Http1Only,23
/**24
* Requires HTTP/2; cleartext must explicitly select prior knowledge or h2c upgrade.25
*/26
Http2Only27
}29
/**30
* Selects how an unencrypted HTTP connection begins.31
*/32
public enum HttpCleartextProtocol {33
/**34
* Begins directly with HTTP/1 messages.35
*/36
Http1,37
/**38
* Begins directly with the HTTP/2 connection preface.39
*/40
Http2PriorKnowledge,41
/**42
* Attempts an explicit HTTP/1.1 h2c upgrade.43
*/44
H2cUpgrade45
}47
/**48
* Origin or proxy TLS trust, protocol bounds, and optional client identity. Default trust uses the49
* system store.50
*/51
public class HttpClientTlsConfig internal constructor(52
/**53
* System or explicit trust anchors used for certificate verification.54
*/55
public val trust: TlsTrustSource = TlsTrustSource.System,56
/**57
* The lowest permitted TLS version.58
*/59
public val minimum: TlsVersion = TlsVersion.Tls12,60
/**61
* The highest permitted TLS version.62
*/63
public val maximum: TlsVersion = TlsVersion.Tls13,64
/**65
* The optional client certificate and private-key identity.66
*/67
public val identity: TlsIdentity? = None68
)70
/**71
* Immutable client defaults for protocols, pooling, transport, policy, storage, and callbacks.72
* Per-call options override selected policies.73
*/74
public class HttpClientConfig internal constructor(75
/**76
* Allowed protocol versions and TLS ALPN selection.77
*/78
public val versionPolicy: HttpVersionPolicy = HttpVersionPolicy.Auto,79
/**80
* Explicit protocol strategy for unencrypted HTTP.81
*/82
public val cleartext: HttpCleartextProtocol = HttpCleartextProtocol.Http1,83
/**84
* The HTTP/1.0 or HTTP/1.1 version emitted for HTTP/1 requests.85
*/86
public val http1RequestVersion: HttpVersion = HttpVersion.Http11,87
/**88
* Origin TLS trust, version bounds, and client identity.89
*/90
public val tls: HttpClientTlsConfig = httpClientTlsConfig(),91
/**92
* Connection and HTTP/2 stream capacities and retirement policy.93
*/94
public val pool: HttpConnectionPoolOptions = httpConnectionPoolOptions(),95
/**96
* Address selection and TCP connection-attempt options.97
*/98
public val tcpConnect: TcpConnectOptions = tcpConnectOptions(),99
/**100
* HTTP/1 parser compatibility policy.101
*/102
public val http1Receive: Http1ReceiveOptions = Http1ReceiveOptions(),103
/**104
* Local HTTP/1 parser limits.105
*/106
public val http1Limits: Http1Limits = Http1Limits(),107
/**108
* HTTP/2 receive compatibility policy.109
*/110
public val http2Receive: Http2ReceiveOptions = Http2ReceiveOptions(),111
/**112
* Local HTTP/2 memory and framing limits.113
*/114
public val http2Limits: Http2Limits = Http2Limits(),115
/**116
* HTTP/2 settings advertised to peers.117
*/118
public val http2Settings: Http2Settings = Http2Settings(),119
/**120
* Response content-decoding policy.121
*/122
public val decoding: HttpDecodingOptions = httpDecodingOptions(),123
/**124
* Call and phase timeouts, including body lifetime.125
*/126
public val timeouts: HttpTimeoutOptions = httpTimeoutOptions(),127
/**128
* Redirect count, enablement, and HTTPS downgrade policy.129
*/130
public val redirects: HttpRedirectOptions = httpRedirectOptions(),131
/**132
* Retry conditions, method eligibility, and backoff policy.133
*/134
public val retries: HttpRetryOptions = httpRetryOptions(),135
/**136
* Origin authentication providers and attempt limit.137
*/138
public val authentication: HttpAuthenticationOptions = httpAuthenticationOptions(),139
/**140
* Per-request proxy selection, direct by default.141
*/142
public val proxy: HttpProxySelector = HttpProxySelector.direct(),143
/**144
* Optional cookie storage; None disables automatic cookie handling.145
*/146
public val cookieJar: CookieJar? = None,147
/**148
* Optional private-response cache and partition settings.149
*/150
public val cache: HttpCacheOptions? = None,151
interceptors: List<HttpInterceptor> = emptyList<HttpInterceptor>(),152
/**153
* Optional suspend callback producing extra fields for each actual attempt.154
*/155
public val onAttempt: (suspend (HttpAttempt) -> List<HttpField>)? = None,156
/**157
* Optional suspend observer for call progress and timing snapshots.158
*/159
public val observer: HttpObserver? = None160
) {161
/**162
* Ordered suspend interceptors around the logical call.163
*/164
public val interceptors: Array<HttpInterceptor> = interceptors.toArray()165
init {166
if (http1RequestVersion == HttpVersion.Http2)167
throw IllegalArgumentException(Some("HTTP/1 request version must be 1.0 or 1.1"))168
if (169
versionPolicy == HttpVersionPolicy.Http1Only && cleartext != HttpCleartextProtocol.Http1170
)171
throw IllegalArgumentException(172
Some("HTTP/1-only policy conflicts with cleartext HTTP/2")173
)174
if (175
cleartext ==176
HttpCleartextProtocol.H2cUpgrade &&177
http1RequestVersion !=178
HttpVersion.Http11179
)180
throw IllegalArgumentException(Some("h2c upgrade requires HTTP/1.1"))181
}182
}184
/**185
* Per-call policy overrides and request-lifetime behavior. None inherits client defaults; duplex186
* requires HTTP/2.187
*/188
public class HttpCallOptions internal constructor(189
/**190
* Allows response processing while upload continues; requires HTTP/2.191
*/192
public val duplex: Boolean = false,193
/**194
* Requests 100-continue gating for a nonempty upload.195
*/196
public val expectContinue: Boolean = false,197
/**198
* How long to wait for Continue before proceeding with the upload; must be nonnegative.199
*/200
public val continueWait: Duration = Duration.seconds(1L),201
/**202
* Overrides the client's response content-decoding policy. None inherits the client default.203
*/204
public val decoding: HttpDecodingOptions? = None,205
/**206
* Overrides the client's call and phase timeouts, including body lifetime. None inherits the207
* client default.208
*/209
public val timeouts: HttpTimeoutOptions? = None,210
/**211
* Suspend callback for informational response heads before the final response.212
*/213
public val onInformational: suspend (HttpResponseHead) -> Unit = suspend { _ -> },214
/**215
* Overrides the client's redirect count, enablement, and HTTPS downgrade policy. None inherits216
* the client default.217
*/218
public val redirects: HttpRedirectOptions? = None,219
/**220
* Overrides the client's retry conditions, method eligibility, and backoff policy. None221
* inherits the client default.222
*/223
public val retries: HttpRetryOptions? = None,224
/**225
* Overrides the client's origin authentication providers and attempt limit. None inherits the226
* client default.227
*/228
public val authentication: HttpAuthenticationOptions? = None,229
/**230
* Overrides the client's per-request proxy selection, direct by default. None inherits the231
* client default.232
*/233
public val proxy: HttpProxySelector? = None,234
/**235
* Whether this call uses the configured cookie jar.236
*/237
public val useCookies: Boolean = true,238
/**239
* Explicit site/navigation context for SameSite-aware cookie selection.240
*/241
public val cookieContext: HttpCookieContext? = None,242
/**243
* The per-call cache policy.244
*/245
public val cacheMode: HttpCacheMode = HttpCacheMode.Default,246
/**247
* Observes this call and all its attempts in addition to the client observer. The request248
* observer runs first; the same observer object configured twice runs only once.249
*/250
public val observer: HttpObserver? = None251
) {252
init {253
if (continueWait < Duration.ZERO)254
throw IllegalArgumentException(Some("negative Continue wait duration"))255
}256
}