1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
+ using System . Diagnostics ;
5
+ using System . Diagnostics . CodeAnalysis ;
4
6
using System . IO . Pipelines ;
5
7
using System . Net ;
6
8
using System . Net . Security ;
10
12
using Microsoft . AspNetCore . Server . Kestrel . Core . Internal ;
11
13
using Microsoft . AspNetCore . Server . Kestrel . Https ;
12
14
using Microsoft . AspNetCore . Server . Kestrel . Https . Internal ;
13
- using Microsoft . Extensions . Hosting ;
14
- using Microsoft . Extensions . Logging ;
15
15
16
16
namespace Microsoft . AspNetCore . Server . Kestrel . Core ;
17
17
@@ -50,10 +50,7 @@ public HttpsConfigurationService(IInitializer initializer)
50
50
bool IHttpsConfigurationService . IsInitialized => _isInitialized || _initializer is not null ;
51
51
52
52
/// <inheritdoc/>
53
- public void Initialize (
54
- IHostEnvironment hostEnvironment ,
55
- ILogger < KestrelServer > serverLogger ,
56
- ILogger < HttpsConnectionMiddleware > httpsLogger )
53
+ public void Initialize ( TlsConfigurationLoader tlsConfigurationLoader )
57
54
{
58
55
if ( _isInitialized )
59
56
{
@@ -62,7 +59,7 @@ public void Initialize(
62
59
63
60
_isInitialized = true ;
64
61
65
- _tlsConfigurationLoader = new TlsConfigurationLoader ( hostEnvironment , serverLogger , httpsLogger ) ;
62
+ _tlsConfigurationLoader = tlsConfigurationLoader ;
66
63
_populateMultiplexedTransportFeatures = PopulateMultiplexedTransportFeaturesWorker ;
67
64
_useHttpsWithDefaults = UseHttpsWithDefaultsWorker ;
68
65
}
@@ -76,41 +73,42 @@ public void ApplyHttpsConfiguration(
76
73
ConfigurationReader configurationReader )
77
74
{
78
75
EnsureInitialized ( ) ;
79
- _tlsConfigurationLoader ! . ApplyHttpsConfiguration ( httpsOptions , endpoint , serverOptions , defaultCertificateConfig , configurationReader ) ;
76
+ _tlsConfigurationLoader . ApplyHttpsConfiguration ( httpsOptions , endpoint , serverOptions , defaultCertificateConfig , configurationReader ) ;
80
77
}
81
78
82
79
/// <inheritdoc/>
83
80
public ListenOptions UseHttpsWithSni ( ListenOptions listenOptions , HttpsConnectionAdapterOptions httpsOptions , EndpointConfig endpoint )
84
81
{
85
82
EnsureInitialized ( ) ;
86
- return _tlsConfigurationLoader ! . UseHttpsWithSni ( listenOptions , httpsOptions , endpoint ) ;
83
+ return _tlsConfigurationLoader . UseHttpsWithSni ( listenOptions , httpsOptions , endpoint ) ;
87
84
}
88
85
89
86
/// <inheritdoc/>
90
87
public CertificateAndConfig ? LoadDefaultCertificate ( ConfigurationReader configurationReader )
91
88
{
92
89
EnsureInitialized ( ) ;
93
- return _tlsConfigurationLoader ! . LoadDefaultCertificate ( configurationReader ) ;
90
+ return _tlsConfigurationLoader . LoadDefaultCertificate ( configurationReader ) ;
94
91
}
95
92
96
93
/// <inheritdoc/>
97
94
public void PopulateMultiplexedTransportFeatures ( FeatureCollection features , ListenOptions listenOptions )
98
95
{
99
96
EnsureInitialized ( ) ;
100
- _populateMultiplexedTransportFeatures ! . Invoke ( features , listenOptions ) ;
97
+ _populateMultiplexedTransportFeatures . Invoke ( features , listenOptions ) ;
101
98
}
102
99
103
100
/// <inheritdoc/>
104
101
public ListenOptions UseHttpsWithDefaults ( ListenOptions listenOptions )
105
102
{
106
103
EnsureInitialized ( ) ;
107
- return _useHttpsWithDefaults ! . Invoke ( listenOptions ) ;
104
+ return _useHttpsWithDefaults . Invoke ( listenOptions ) ;
108
105
}
109
106
110
107
/// <summary>
111
108
/// If this instance has not been initialized, initialize it if possible and throw otherwise.
112
109
/// </summary>
113
110
/// <exception cref="InvalidOperationException">If initialization is not possible.</exception>
111
+ [ MemberNotNull ( nameof ( _useHttpsWithDefaults ) , nameof ( _tlsConfigurationLoader ) , nameof ( _populateMultiplexedTransportFeatures ) ) ]
114
112
private void EnsureInitialized ( )
115
113
{
116
114
if ( ! _isInitialized )
@@ -124,6 +122,10 @@ private void EnsureInitialized()
124
122
throw new InvalidOperationException ( CoreStrings . NeedHttpsConfiguration ) ;
125
123
}
126
124
}
125
+
126
+ Debug . Assert ( _useHttpsWithDefaults != null ) ;
127
+ Debug . Assert ( _tlsConfigurationLoader != null ) ;
128
+ Debug . Assert ( _populateMultiplexedTransportFeatures != null ) ;
127
129
}
128
130
129
131
/// <summary>
@@ -228,24 +230,17 @@ internal interface IInitializer
228
230
/// <inheritdoc/>
229
231
internal sealed class Initializer : IInitializer
230
232
{
231
- private readonly IHostEnvironment _hostEnvironment ;
232
- private readonly ILogger < KestrelServer > _serverLogger ;
233
- private readonly ILogger < HttpsConnectionMiddleware > _httpsLogger ;
234
-
235
- public Initializer (
236
- IHostEnvironment hostEnvironment ,
237
- ILogger < KestrelServer > serverLogger ,
238
- ILogger < HttpsConnectionMiddleware > httpsLogger )
233
+ private readonly TlsConfigurationLoader _configurationLoader ;
234
+
235
+ public Initializer ( TlsConfigurationLoader configurationLoader )
239
236
{
240
- _hostEnvironment = hostEnvironment ;
241
- _serverLogger = serverLogger ;
242
- _httpsLogger = httpsLogger ;
237
+ _configurationLoader = configurationLoader ;
243
238
}
244
239
245
240
/// <inheritdoc/>
246
241
public void Initialize ( IHttpsConfigurationService httpsConfigurationService )
247
242
{
248
- httpsConfigurationService . Initialize ( _hostEnvironment , _serverLogger , _httpsLogger ) ;
243
+ httpsConfigurationService . Initialize ( _configurationLoader ) ;
249
244
}
250
245
}
251
246
}
0 commit comments