@@ -50,13 +50,12 @@ public sealed class HeaderList : IList<Header>
50
50
// this table references the first header of each field
51
51
readonly Dictionary < string , Header > table ;
52
52
readonly List < Header > headers ;
53
- bool hasBodySeparator ;
54
53
55
- internal HeaderList ( ParserOptions options , bool hasBodySeparator )
54
+ internal HeaderList ( ParserOptions options )
56
55
{
57
56
table = new Dictionary < string , Header > ( MimeUtils . OrdinalIgnoreCase ) ;
58
- this . hasBodySeparator = hasBodySeparator ;
59
57
headers = new List < Header > ( ) ;
58
+ HasBodySeparator = true ;
60
59
Options = options ;
61
60
}
62
61
@@ -66,10 +65,21 @@ internal HeaderList (ParserOptions options, bool hasBodySeparator)
66
65
/// <remarks>
67
66
/// Creates a new empty header list.
68
67
/// </remarks>
69
- public HeaderList ( ) : this ( ParserOptions . Default . Clone ( ) , true )
68
+ public HeaderList ( ) : this ( ParserOptions . Default . Clone ( ) )
70
69
{
71
70
}
72
71
72
+ /// <summary>
73
+ /// Get or set whether or not the header list has a body separator.
74
+ /// </summary>
75
+ /// <remarks>
76
+ /// Get or set whether or not the header list has a body separator.
77
+ /// </remarks>
78
+ /// <value><see langword="true"/> if the header list has a body separator; otherwise, <see langword="false"/>.</value>
79
+ internal bool HasBodySeparator {
80
+ get ; set ;
81
+ }
82
+
73
83
/// <summary>
74
84
/// Add a header with the specified field and value.
75
85
/// </summary>
@@ -456,6 +466,8 @@ public void RemoveAll (HeaderId id)
456
466
if ( ! table . Remove ( id . ToHeaderName ( ) ) )
457
467
return ;
458
468
469
+ HasBodySeparator = true ;
470
+
459
471
for ( int i = headers . Count - 1 ; i >= 0 ; i -- ) {
460
472
if ( headers [ i ] . Id != id )
461
473
continue ;
@@ -485,6 +497,8 @@ public void RemoveAll (string field)
485
497
if ( ! table . Remove ( field ) )
486
498
return ;
487
499
500
+ HasBodySeparator = true ;
501
+
488
502
for ( int i = headers . Count - 1 ; i >= 0 ; i -- ) {
489
503
if ( ! headers [ i ] . Field . Equals ( field , StringComparison . OrdinalIgnoreCase ) )
490
504
continue ;
@@ -706,7 +720,7 @@ public void WriteTo (FormatOptions options, Stream stream, CancellationToken can
706
720
filtered . Flush ( cancellationToken ) ;
707
721
}
708
722
709
- if ( ! hasBodySeparator )
723
+ if ( ! HasBodySeparator )
710
724
return ;
711
725
712
726
if ( stream is ICancellableStream cancellable ) {
@@ -763,7 +777,7 @@ public async Task WriteToAsync (FormatOptions options, Stream stream, Cancellati
763
777
await filtered . FlushAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
764
778
}
765
779
766
- if ( ! hasBodySeparator )
780
+ if ( ! HasBodySeparator )
767
781
return ;
768
782
769
783
await stream . WriteAsync ( options . NewLineBytes , 0 , options . NewLineBytes . Length , cancellationToken ) . ConfigureAwait ( false ) ;
@@ -858,6 +872,7 @@ public void Add (Header header)
858
872
859
873
header . Changed += HeaderChanged ;
860
874
headers . Add ( header ) ;
875
+ HasBodySeparator = true ;
861
876
862
877
OnChanged ( header , HeaderListChangedAction . Added ) ;
863
878
}
@@ -873,6 +888,7 @@ public void Clear ()
873
888
foreach ( var header in headers )
874
889
header . Changed -= HeaderChanged ;
875
890
891
+ HasBodySeparator = true ;
876
892
headers . Clear ( ) ;
877
893
table . Clear ( ) ;
878
894
@@ -956,6 +972,7 @@ public bool Remove (Header header)
956
972
}
957
973
958
974
headers . RemoveAt ( index ) ;
975
+ HasBodySeparator = true ;
959
976
960
977
OnChanged ( header , HeaderListChangedAction . Removed ) ;
961
978
@@ -1002,6 +1019,8 @@ public void Replace (Header header)
1002
1019
table [ header . Field ] = header ;
1003
1020
headers [ i ] = header ;
1004
1021
1022
+ HasBodySeparator = true ;
1023
+
1005
1024
OnChanged ( first , HeaderListChangedAction . Removed ) ;
1006
1025
OnChanged ( header , HeaderListChangedAction . Added ) ;
1007
1026
}
@@ -1063,6 +1082,7 @@ public void Insert (int index, Header header)
1063
1082
1064
1083
headers . Insert ( index , header ) ;
1065
1084
header . Changed += HeaderChanged ;
1085
+ HasBodySeparator = true ;
1066
1086
1067
1087
OnChanged ( header , HeaderListChangedAction . Added ) ;
1068
1088
}
@@ -1099,6 +1119,7 @@ public void RemoveAt (int index)
1099
1119
}
1100
1120
1101
1121
headers . RemoveAt ( index ) ;
1122
+ HasBodySeparator = true ;
1102
1123
1103
1124
OnChanged ( header , HeaderListChangedAction . Removed ) ;
1104
1125
}
@@ -1169,6 +1190,7 @@ public Header this [int index] {
1169
1190
}
1170
1191
1171
1192
headers [ index ] = value ;
1193
+ HasBodySeparator = true ;
1172
1194
1173
1195
if ( header . Field . Equals ( value . Field , StringComparison . OrdinalIgnoreCase ) ) {
1174
1196
OnChanged ( value , HeaderListChangedAction . Changed ) ;
0 commit comments