scoop:scoop.http.server:0.1.0
src/server_options.scoop
Selected production source · src/server_options.scoop
1
package scoop.http.server3
import scoop.http.*4
import scoop.time.Duration5
import scoop.tls.TlsServerContext7
/** Transport, capacity and timeout configuration for an owned HTTP server. */8
public class HttpServerOptions internal constructor(9
/** Shared TLS configuration, retained by the caller; None selects cleartext. */10
public val tls: TlsServerContext? = None,11
/** Whether TLS without negotiated ALPN may use HTTP/1. */12
public val allowHttp1Fallback: Boolean = true,13
/** Whether cleartext connections may select HTTP/2 prior knowledge by their preface. */14
public val allowCleartextHttp2: Boolean = false,15
/** Whether TLS connections may select h2 through ALPN. */16
public val allowTlsHttp2: Boolean = true,17
/** Maximum owned TCP connections, including handshakes and idle keep-alive connections. */18
public val maxConnections: Long = 1024L,19
/** Maximum concurrent application requests, including response execution and cleanup. */20
public val maxActiveRequests: Long = 256L,21
/** Maximum reserved or active upgraded sessions, held until their cleanup ends. */22
public val maxWebSocketSessions: Long = maxConnections,23
/** Shared application-request limits, lifetime and completion observation. */24
public val request: HttpRequestOptions = httpRequestOptions(),25
/** Total TLS handshake time, or None to disable this deadline. */26
public val tlsHandshakeTimeout: Duration? = Some(Duration.seconds(10)),27
/** Total time to receive the first complete request head, including cleartext probing. */28
public val firstRequestHeadTimeout: Duration? = Some(Duration.seconds(10)),29
/** Total time for each recognized initial HTTP/2 HEADERS block, including CONTINUATION. */30
public val http2HeadTimeout: Duration? = Some(Duration.seconds(10)),31
/** Idle connection limit; HTTP/1 includes the next head, HTTP/2 excludes active requests. */32
public val keepAliveIdleTimeout: Duration? = Some(Duration.seconds(60)),33
/** Read stagnation limit applied by the HTTP transport to request input. */34
public val bodyReadIdle: Duration? = Some(Duration.seconds(30)),35
/** Write stagnation limit applied by the HTTP transport to response output. */36
public val responseWriteIdle: Duration? = Some(Duration.seconds(30)),37
/** Default natural-drain period before forced cancellation and cleanup. */38
public val gracefulShutdownTimeout: Duration = Duration.seconds(30),39
/** HTTP/1 receive behavior; strict defaults are preserved. */40
public val http1Receive: Http1ReceiveOptions = Http1ReceiveOptions(),41
/** Existing HTTP/1 start-line, field and buffering limits. */42
public val http1Limits: Http1Limits = Http1Limits(),43
/** HTTP/2 receive behavior, rejecting invalid regular fields by default. */44
public val http2Receive: Http2ReceiveOptions =45
Http2ReceiveOptions(invalidRegularField = Http2InvalidRegularField.RejectStream),46
/** Existing HTTP/2 header and pending output limits. */47
public val http2Limits: Http2Limits = Http2Limits(),48
/** Local HTTP/2 settings, including the bounded incoming request queue. */49
public val http2Settings: Http2Settings = Http2Settings(),50
/** Observes an upgraded session only after business work and transport cleanup have ended. */51
public val onWebSocketCompleted: ((HttpWebSocketCompletion) -> Unit)? = None,52
/** Observes isolated connection failures without controlling another connection. */53
public val onConnectionError: ((HttpConnectionInfo, Throwable) -> Unit)? = None54
) {55
init {56
if (maxConnections <= 0L || maxActiveRequests <= 0L || maxWebSocketSessions <= 0L)57
throw IllegalArgumentException(Some("invalid HTTP server capacity"))58
for (59
value in [60
tlsHandshakeTimeout,61
firstRequestHeadTimeout,62
http2HeadTimeout,63
keepAliveIdleTimeout,64
bodyReadIdle,65
responseWriteIdle,66
Some(gracefulShutdownTimeout)67
]68
)69
requireServerDuration(value)70
}71
}73
internal fun requireServerDuration(value: Duration?) {74
if (present(value) && value!! < Duration.ZERO)75
throw IllegalArgumentException(Some("negative HTTP server duration"))76
}