@@ -13,7 +13,8 @@ internal static class ResponseHeadersHelper
13
13
nameof ( BaseResponseHeadersConfigurationOptions . ContentType ) ,
14
14
nameof ( BaseResponseHeadersConfigurationOptions . ContentTypeContain ) ,
15
15
nameof ( BaseResponseHeadersConfigurationOptions . ContentTypeStartWith ) ,
16
- nameof ( BaseResponseHeadersConfigurationOptions . Headers ) ,
16
+ // nameof(BaseResponseHeadersConfigurationOptions.Headers), binder cause bug between array and key value
17
+ "Headers" ,
17
18
nameof ( BaseResponseHeadersConfigurationOptions . StatusCode ) ,
18
19
nameof ( ResponseHeadersConfigurationOptions . IsEnabled ) ,
19
20
"IsAnyContentType" , // legacy value
@@ -67,9 +68,14 @@ private static ResponseHandlerEntry ParseHandler(BaseResponseHeadersConfiguratio
67
68
{
68
69
var headers = new Dictionary < string , string > ( ) ;
69
70
70
- foreach ( var item in options . Headers ?? [ ] )
71
+ foreach ( var item in configuration . GetSection ( " Headers" ) . GetChildren ( ) )
71
72
{
72
- if ( TryParseKeyValue ( item , out var key , out var value )
73
+ if ( item . Value is { } value1
74
+ && item . Key is { } key1
75
+ && ! string . IsNullOrEmpty ( key1 )
76
+ && ! string . IsNullOrEmpty ( value1 )
77
+ && int . TryParse ( key1 , out var _ )
78
+ && TryParseKeyValue ( value1 , out var key , out var value )
73
79
&& ! string . IsNullOrEmpty ( key )
74
80
&& ! string . IsNullOrEmpty ( value ) )
75
81
{
@@ -115,11 +121,15 @@ private static ResponseHandlerEntry ParseHandler(BaseResponseHeadersConfiguratio
115
121
headers [ key ] = value ;
116
122
}
117
123
}
118
- else if ( nameof ( BaseResponseHeadersConfigurationOptions . Headers ) . Equals ( key , DefaultStringComparison ) )
124
+ else if ( " Headers" . Equals ( key , DefaultStringComparison ) ) // nameof(BaseResponseHeadersConfigurationOptions.Headers )
119
125
{
120
126
foreach ( var item1 in item . GetChildren ( ) )
121
127
{
122
- if ( item1 . Value is { } value1 && item1 . Key is { } key1 && ! string . IsNullOrEmpty ( key1 ) && ! string . IsNullOrEmpty ( value1 ) && ! int . TryParse ( key1 , out var _ ) )
128
+ if ( item1 . Value is { } value1
129
+ && item1 . Key is { } key1
130
+ && ! string . IsNullOrEmpty ( key1 )
131
+ && ! string . IsNullOrEmpty ( value1 )
132
+ && ! int . TryParse ( key1 , out var _ ) )
123
133
{
124
134
headers [ key1 ] = value1 ;
125
135
}
0 commit comments