1313using Microsoft . AspNetCore . Certificates . Generation ;
1414using Microsoft . AspNetCore . Http ;
1515using Microsoft . AspNetCore . Server . Kestrel . Core . Internal ;
16- using Microsoft . AspNetCore . Server . Kestrel . Core . Internal . Infrastructure ;
1716using Microsoft . AspNetCore . Server . Kestrel . Https ;
1817using Microsoft . Extensions . Configuration ;
1918using Microsoft . Extensions . DependencyInjection ;
@@ -26,11 +25,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core
2625 /// </summary>
2726 public class KestrelServerOptions
2827 {
29- // Internal to fast-path header decoding when RequestHeaderEncodingSelector is unchanged.
30- internal static readonly UTF8EncodingSealed DefaultRequestHeaderEncoding = new UTF8EncodingSealed ( ) ;
31- internal static readonly Func < string , Encoding > DefaultRequestHeaderEncodingSelector = _ => DefaultRequestHeaderEncoding ;
28+ // internal to fast-path header decoding when RequestHeaderEncodingSelector is unchanged.
29+ internal static readonly Func < string , Encoding ? > DefaultRequestHeaderEncodingSelector = _ => null ;
3230 internal static readonly Func < string , Encoding > DefaultLatin1RequestHeaderEncodingSelector = _ => Encoding . Latin1 ;
3331
32+ private Func < string , Encoding ? > _requestHeaderEncodingSelector = DefaultRequestHeaderEncodingSelector ;
33+
3434 // The following two lists configure the endpoints that Kestrel should listen to. If both lists are empty, the "urls" config setting (e.g. UseUrls) is used.
3535 internal List < ListenOptions > CodeBackedListenOptions { get ; } = new List < ListenOptions > ( ) ;
3636 internal List < ListenOptions > ConfigurationBackedListenOptions { get ; } = new List < ListenOptions > ( ) ;
@@ -86,10 +86,11 @@ public class KestrelServerOptions
8686 /// Gets or sets a callback that returns the <see cref="Encoding"/> to decode the value for the specified request header name,
8787 /// or <see langword="null"/> to use the default <see cref="UTF8Encoding"/>.
8888 /// </summary>
89- /// <remarks>
90- /// Defaults to returning a <see langword="null"/> for all headers.
91- /// </remarks>
92- public Func < string , Encoding ? > RequestHeaderEncodingSelector { get ; set ; } = DefaultRequestHeaderEncodingSelector ;
89+ public Func < string , Encoding ? > RequestHeaderEncodingSelector
90+ {
91+ get => _requestHeaderEncodingSelector ;
92+ set => _requestHeaderEncodingSelector = value ?? throw new ArgumentNullException ( nameof ( value ) ) ;
93+ }
9394
9495 /// <summary>
9596 /// Enables the Listen options callback to resolve and use services registered by the application during startup.
@@ -144,13 +145,12 @@ public void ConfigureEndpointDefaults(Action<ListenOptions> configureOptions)
144145
145146 internal Func < string , Encoding ? > GetRequestHeaderEncodingSelector ( )
146147 {
147- if ( ReferenceEquals ( RequestHeaderEncodingSelector , DefaultRequestHeaderEncodingSelector ) && Latin1RequestHeaders )
148+ if ( ReferenceEquals ( _requestHeaderEncodingSelector , DefaultRequestHeaderEncodingSelector ) && Latin1RequestHeaders )
148149 {
149150 return DefaultLatin1RequestHeaderEncodingSelector ;
150151 }
151152
152- return RequestHeaderEncodingSelector
153- ?? throw new InvalidOperationException ( $ "{ nameof ( KestrelServerOptions ) } .{ nameof ( RequestHeaderEncodingSelector ) } must not be set to null.") ;
153+ return _requestHeaderEncodingSelector ;
154154 }
155155
156156 internal void ApplyEndpointDefaults ( ListenOptions listenOptions )
@@ -256,7 +256,6 @@ private void EnsureDefaultCert()
256256 /// This will only reload endpoints defined in the "Endpoints" section of your <paramref name="config"/>. Endpoints defined in code will not be reloaded.
257257 /// </param>
258258 /// <returns>A <see cref="KestrelConfigurationLoader"/> for further endpoint configuration.</returns>
259-
260259 public KestrelConfigurationLoader Configure ( IConfiguration config , bool reloadOnChange )
261260 {
262261 var loader = new KestrelConfigurationLoader ( this , config , reloadOnChange ) ;
0 commit comments