scoop:scoop.http.client:0.1.0
src/timeouts/options.scoop
Selected production source · src/timeouts/options.scoop
1
package scoop.http.client3
import scoop.time.Duration5
/**6
* Optional nonnegative deadlines for the total call and individual waits. None disables that7
* bound; total includes upload, response body, and cleanup.8
*/9
public class HttpTimeoutOptions internal constructor(10
/**11
* Optional timeout for the entire call through body and cleanup; None disables this bound.12
*/13
public val total: Duration? = None,14
/**15
* Optional timeout for waiting for pool capacity; None disables this bound.16
*/17
public val poolAcquire: Duration? = None,18
/**19
* Optional timeout for waiting for final response headers; None disables this bound.20
*/21
public val responseHeaders: Duration? = None,22
/**23
* Optional timeout for resolving an address; None disables this bound.24
*/25
public val resolve: Duration? = Some(Duration.seconds(30L)),26
/**27
* Optional timeout for establishing TCP; None disables this bound.28
*/29
public val connect: Duration? = Some(Duration.seconds(30L)),30
/**31
* Optional timeout for performing a TLS handshake; None disables this bound.32
*/33
public val tlsHandshake: Duration? = Some(Duration.seconds(30L)),34
/**35
* Optional timeout for waiting without incoming progress; None disables this bound.36
*/37
public val readIdle: Duration? = None,38
/**39
* Optional timeout for waiting without outgoing progress; None disables this bound.40
*/41
public val writeIdle: Duration? = None,42
/**43
* Optional timeout for performing CONNECT or SOCKS5 negotiation; None disables this bound.44
*/45
public val proxyHandshake: Duration? = Some(Duration.seconds(30L))46
) {47
init {48
for (49
duration in [50
total,51
poolAcquire,52
responseHeaders,53
resolve,54
connect,55
tlsHandshake,56
readIdle,57
writeIdle,58
proxyHandshake59
]60
) {61
if (duration != None && duration!! < Duration.ZERO)62
throw IllegalArgumentException(Some("HTTP timeout must be nonnegative"))63
}64
}65
}67
/**68
* The call phase whose configured deadline expired.69
*/70
public enum HttpTimeoutPhase {71
/**72
* The deadline expired while the entire call through body and cleanup.73
*/74
Total,75
/**76
* The deadline expired while waiting for pool capacity.77
*/78
PoolAcquire,79
/**80
* The deadline expired while waiting for final response headers.81
*/82
ResponseHeaders,83
/**84
* The deadline expired while resolving an address.85
*/86
Resolve,87
/**88
* The deadline expired while establishing TCP.89
*/90
Connect,91
/**92
* The deadline expired while performing a TLS handshake.93
*/94
TlsHandshake,95
/**96
* The deadline expired while waiting without incoming progress.97
*/98
ReadIdle,99
/**100
* The deadline expired while waiting without outgoing progress.101
*/102
WriteIdle,103
/**104
* The deadline expired while performing CONNECT or SOCKS5 negotiation.105
*/106
ProxyHandshake107
}109
/**110
* An expired deadline with configured limit, elapsed time, byte progress, and optional underlying111
* cause.112
*/113
public class HttpTimeoutException internal constructor(114
/**115
* The phase whose deadline expired.116
*/117
public val phase: HttpTimeoutPhase,118
/**119
* The configured deadline duration.120
*/121
public val limit: Duration,122
/**123
* The measured duration for that deadline.124
*/125
public val elapsed: Duration,126
/**127
* Request body bytes transferred before timeout.128
*/129
public val requestBodyBytes: Long,130
/**131
* Response bytes received before content decoding.132
*/133
public val encodedResponseBodyBytes: Long,134
/**135
* Response bytes delivered after content decoding.136
*/137
public val responseBodyBytes: Long,138
/**139
* The underlying failure associated with the timeout, if any.140
*/141
public val cause: Throwable? = None142
): Exception(Some("HTTP " + httpTimeoutPhaseName(phase) + " timeout"))144
private fun httpTimeoutPhaseName(phase: HttpTimeoutPhase): String =145
when (phase) {146
case Total -> "total"147
case PoolAcquire -> "pool acquisition"148
case ResponseHeaders -> "response headers"149
case Resolve -> "address resolution"150
case Connect -> "TCP connection"151
case TlsHandshake -> "TLS handshake"152
case ReadIdle -> "read idle"153
case WriteIdle -> "write idle"154
case ProxyHandshake -> "proxy handshake"155
}