11public import HTTPTypes
22public import Logging
3+ import NIOCertificateReloading
34import NIOCore
45import NIOHTTP1
56import NIOHTTP2
@@ -164,21 +165,63 @@ public final class Server<RequestHandler: HTTPServerRequestHandler> {
164165 )
165166 }
166167
167- switch configuration. tlSConfiguration . backing {
168- case . insecure :
168+ switch configuration. transportSecurity . backing {
169+ case . plaintext :
169170 try await Self . serveInsecureHTTP1_1 (
170171 bindTarget: configuration. bindTarget,
171172 handler: handler,
172173 asyncChannelConfiguration: asyncChannelConfiguration,
173174 logger: logger
174175 )
175176
176- case . certificateChainAndPrivateKey( let certificateChain, let privateKey) :
177- let http2Config = NIOHTTP2Handler . Configuration ( httpServerHTTP2Configuration: configuration. http2)
177+ case . reloadingTLS( let certificateReloader) :
178+ let http2Config = NIOHTTP2Handler . Configuration (
179+ httpServerHTTP2Configuration: configuration. http2
180+ )
181+
182+ var tlsConfiguration : TLSConfiguration = try . makeServerConfiguration(
183+ certificateReloader: certificateReloader
184+ )
185+ tlsConfiguration. applicationProtocols = [ " h2 " , " http/1.1 " ]
186+
178187 try await Self . serveSecureUpgrade (
179188 bindTarget: configuration. bindTarget,
189+ tlsConfiguration: tlsConfiguration,
190+ handler: handler,
191+ asyncChannelConfiguration: asyncChannelConfiguration,
192+ http2Configuration: http2Config,
193+ logger: logger
194+ )
195+
196+ case . staticTLS( let certificateChain, let privateKey) :
197+ let http2Config = NIOHTTP2Handler . Configuration (
198+ httpServerHTTP2Configuration: configuration. http2
199+ )
200+
201+ let certificateChain = try certificateChain
202+ . map {
203+ try NIOSSLCertificate (
204+ bytes: $0. serializeAsPEM ( ) . derBytes,
205+ format: . der
206+ )
207+ }
208+ . map { NIOSSLCertificateSource . certificate ( $0) }
209+ let privateKey = NIOSSLPrivateKeySource . privateKey (
210+ try NIOSSLPrivateKey (
211+ bytes: privateKey. serializeAsPEM ( ) . derBytes,
212+ format: . der
213+ )
214+ )
215+
216+ var tlsConfiguration : TLSConfiguration = . makeServerConfiguration(
180217 certificateChain: certificateChain,
181- privateKey: privateKey,
218+ privateKey: privateKey
219+ )
220+ tlsConfiguration. applicationProtocols = [ " h2 " , " http/1.1 " ]
221+
222+ try await Self . serveSecureUpgrade (
223+ bindTarget: configuration. bindTarget,
224+ tlsConfiguration: tlsConfiguration,
182225 handler: handler,
183226 asyncChannelConfiguration: asyncChannelConfiguration,
184227 http2Configuration: http2Config,
@@ -225,8 +268,7 @@ public final class Server<RequestHandler: HTTPServerRequestHandler> {
225268
226269 private static func serveSecureUpgrade(
227270 bindTarget: HTTPServerConfiguration . BindTarget ,
228- certificateChain: [ Certificate ] ,
229- privateKey: Certificate . PrivateKey ,
271+ tlsConfiguration: TLSConfiguration ,
230272 handler: RequestHandler ,
231273 asyncChannelConfiguration: NIOAsyncChannel < HTTPRequestPart , HTTPResponsePart > . Configuration ,
232274 http2Configuration: NIOHTTP2Handler . Configuration ,
@@ -238,27 +280,6 @@ public final class Server<RequestHandler: HTTPServerRequestHandler> {
238280 . serverChannelOption ( . socketOption( . so_reuseaddr) , value: 1 )
239281 . bind ( host: host, port: port) { channel in
240282 channel. eventLoop. makeCompletedFuture {
241- let certificateChain = try certificateChain
242- . map {
243- try NIOSSLCertificate (
244- bytes: $0. serializeAsPEM ( ) . derBytes,
245- format: . der
246- )
247- }
248- . map { NIOSSLCertificateSource . certificate ( $0) }
249- let privateKey = NIOSSLPrivateKeySource . privateKey (
250- try NIOSSLPrivateKey (
251- bytes: privateKey. serializeAsPEM ( ) . derBytes,
252- format: . der
253- )
254- )
255-
256- var tlsConfiguration : TLSConfiguration = . makeServerConfiguration(
257- certificateChain: certificateChain,
258- privateKey: privateKey
259- )
260- tlsConfiguration. applicationProtocols = [ " h2 " , " http/1.1 " ]
261-
262283 try channel. pipeline. syncOperations
263284 . addHandler (
264285 NIOSSLServerHandler (
0 commit comments