Scoop API

scoop:scoop.http.server:0.1.0

src/http_server_options_builder.scoop

Selected production source · src/http_server_options_builder.scoop

1package scoop.http.server
3import scoop.http.*
4import scoop.time.Duration
5import scoop.tls.TlsServerContext
6import scoop.http.asyncio.*
8/** Configures one complete value; execution remains explicit. */
9public fun httpServerOptions(
10 configure: HttpServerOptionsBuilder.() -> Unit = {}
11): HttpServerOptions {
12 val builder = HttpServerOptionsBuilder()
13 builder.configure()
14 return builder.snapshot()
17public fun HttpServerOptions.copy(
18 configure: HttpServerOptionsBuilder.() -> Unit = {}
19): HttpServerOptions {
20 val builder = HttpServerOptionsBuilder()
21 builder.tls = this.tls
22 builder.allowHttp1Fallback = this.allowHttp1Fallback
23 builder.allowCleartextHttp2 = this.allowCleartextHttp2
24 builder.allowTlsHttp2 = this.allowTlsHttp2
25 builder.maxConnections = this.maxConnections
26 builder.maxActiveRequests = this.maxActiveRequests
27 builder.maxWebSocketSessions = this.maxWebSocketSessions
28 builder.request = this.request
29 builder.tlsHandshakeTimeout = this.tlsHandshakeTimeout
30 builder.firstRequestHeadTimeout = this.firstRequestHeadTimeout
31 builder.http2HeadTimeout = this.http2HeadTimeout
32 builder.keepAliveIdleTimeout = this.keepAliveIdleTimeout
33 builder.bodyReadIdle = this.bodyReadIdle
34 builder.responseWriteIdle = this.responseWriteIdle
35 builder.gracefulShutdownTimeout = this.gracefulShutdownTimeout
36 builder.http1Receive = this.http1Receive
37 builder.http1Limits = this.http1Limits
38 builder.http2Receive = this.http2Receive
39 builder.http2Limits = this.http2Limits
40 builder.http2Settings = this.http2Settings
41 builder.onWebSocketCompleted = this.onWebSocketCompleted
42 builder.onConnectionError = this.onConnectionError
43 builder.configure()
44 return builder.snapshot()
47public class HttpServerOptionsBuilder internal constructor() {
48 public var tls: TlsServerContext? = None
49 public var allowHttp1Fallback: Boolean = true
50 public var allowCleartextHttp2: Boolean = false
51 public var allowTlsHttp2: Boolean = true
52 public var maxConnections: Long = 1024L
53 public var maxActiveRequests: Long = 256L
54 private var configuredMaxWebSocketSessions: Long? = None
55 public var maxWebSocketSessions: Long
56 get() = configuredMaxWebSocketSessions ?: maxConnections
57 set(value) {
58 configuredMaxWebSocketSessions = Some(value)
59 }
60 public var request: HttpRequestOptions = httpRequestOptions()
61 public var tlsHandshakeTimeout: Duration? = Some(Duration.seconds(10))
62 public var firstRequestHeadTimeout: Duration? = Some(Duration.seconds(10))
63 public var http2HeadTimeout: Duration? = Some(Duration.seconds(10))
64 public var keepAliveIdleTimeout: Duration? = Some(Duration.seconds(60))
65 public var bodyReadIdle: Duration? = Some(Duration.seconds(30))
66 public var responseWriteIdle: Duration? = Some(Duration.seconds(30))
67 public var gracefulShutdownTimeout: Duration = Duration.seconds(30)
68 public var http1Receive: Http1ReceiveOptions = Http1ReceiveOptions()
69 public var http1Limits: Http1Limits = Http1Limits()
70 public var http2Receive: Http2ReceiveOptions =
71 Http2ReceiveOptions(invalidRegularField = Http2InvalidRegularField.RejectStream)
72 public var http2Limits: Http2Limits = Http2Limits()
73 public var http2Settings: Http2Settings = Http2Settings()
74 public var onWebSocketCompleted: ((HttpWebSocketCompletion) -> Unit)? = None
75 public var onConnectionError: ((HttpConnectionInfo, Throwable) -> Unit)? = None
77 public fun request(configure: HttpRequestOptionsBuilder.() -> Unit): Unit {
78 request = request.copy(configure)
79 }
81 public fun http1Receive(configure: Http1ReceiveOptionsBuilder.() -> Unit): Unit {
82 http1Receive = http1Receive.copy(configure)
83 }
85 public fun http1Limits(configure: Http1LimitsBuilder.() -> Unit): Unit {
86 http1Limits = http1Limits.copy(configure)
87 }
89 public fun http2Receive(configure: Http2ReceiveOptionsBuilder.() -> Unit): Unit {
90 http2Receive = http2Receive.copy(configure)
91 }
93 public fun http2Limits(configure: Http2LimitsBuilder.() -> Unit): Unit {
94 http2Limits = http2Limits.copy(configure)
95 }
97 public fun http2Settings(configure: Http2SettingsBuilder.() -> Unit): Unit {
98 http2Settings = http2Settings.copy(configure)
99 }
100 internal fun snapshot(): HttpServerOptions =
101 HttpServerOptions(
102 tls,
103 allowHttp1Fallback,
104 allowCleartextHttp2,
105 allowTlsHttp2,
106 maxConnections,
107 maxActiveRequests,
108 maxWebSocketSessions,
109 request,
110 tlsHandshakeTimeout,
111 firstRequestHeadTimeout,
112 http2HeadTimeout,
113 keepAliveIdleTimeout,
114 bodyReadIdle,
115 responseWriteIdle,
116 gracefulShutdownTimeout,
117 http1Receive,
118 http1Limits,
119 http2Receive,
120 http2Limits,
121 http2Settings,
122 onWebSocketCompleted,
123 onConnectionError
124 )