3
3
4
4
using System ;
5
5
using System . Buffers ;
6
+ using System . Collections ;
6
7
using System . Collections . Generic ;
7
8
using System . Globalization ;
8
9
using System . IO ;
@@ -210,6 +211,34 @@ await ExpectAsync(Http2FrameType.HEADERS,
210
211
await StopConnectionAsync ( expectedLastStreamId : 3 , ignoreNonGoAwayFrames : false ) ;
211
212
}
212
213
214
+ private class ResponseTrailersWrapper : IHeaderDictionary
215
+ {
216
+ readonly IHeaderDictionary _innerHeaders ;
217
+
218
+ public ResponseTrailersWrapper ( IHeaderDictionary headers )
219
+ {
220
+ _innerHeaders = headers ;
221
+ }
222
+
223
+ public StringValues this [ string key ] { get => _innerHeaders [ key ] ; set => _innerHeaders [ key ] = value ; }
224
+ public long ? ContentLength { get => _innerHeaders . ContentLength ; set => _innerHeaders . ContentLength = value ; }
225
+ public ICollection < string > Keys => _innerHeaders . Keys ;
226
+ public ICollection < StringValues > Values => _innerHeaders . Values ;
227
+ public int Count => _innerHeaders . Count ;
228
+ public bool IsReadOnly => _innerHeaders . IsReadOnly ;
229
+ public void Add ( string key , StringValues value ) => _innerHeaders . Add ( key , value ) ;
230
+ public void Add ( KeyValuePair < string , StringValues > item ) => _innerHeaders . Add ( item ) ;
231
+ public void Clear ( ) => _innerHeaders . Clear ( ) ;
232
+ public bool Contains ( KeyValuePair < string , StringValues > item ) => _innerHeaders . Contains ( item ) ;
233
+ public bool ContainsKey ( string key ) => _innerHeaders . ContainsKey ( key ) ;
234
+ public void CopyTo ( KeyValuePair < string , StringValues > [ ] array , int arrayIndex ) => _innerHeaders . CopyTo ( array , arrayIndex ) ;
235
+ public IEnumerator < KeyValuePair < string , StringValues > > GetEnumerator ( ) => _innerHeaders . GetEnumerator ( ) ;
236
+ public bool Remove ( string key ) => _innerHeaders . Remove ( key ) ;
237
+ public bool Remove ( KeyValuePair < string , StringValues > item ) => _innerHeaders . Remove ( item ) ;
238
+ public bool TryGetValue ( string key , out StringValues value ) => _innerHeaders . TryGetValue ( key , out value ) ;
239
+ IEnumerator IEnumerable . GetEnumerator ( ) => _innerHeaders . GetEnumerator ( ) ;
240
+ }
241
+
213
242
[ Fact ]
214
243
public async Task ResponseTrailers_MultipleStreams_Reset ( )
215
244
{
@@ -227,7 +256,18 @@ await InitializeConnectionAsync(context =>
227
256
{
228
257
requestCount ++ ;
229
258
230
- var trailers = context . Features . Get < IHttpResponseTrailersFeature > ( ) . Trailers ;
259
+ var trailersFeature = context . Features . Get < IHttpResponseTrailersFeature > ( ) ;
260
+
261
+ IHeaderDictionary trailers ;
262
+ if ( requestCount == 1 )
263
+ {
264
+ trailers = new ResponseTrailersWrapper ( trailersFeature . Trailers ) ;
265
+ trailersFeature . Trailers = trailers ;
266
+ }
267
+ else
268
+ {
269
+ trailers = trailersFeature . Trailers ;
270
+ }
231
271
trailers [ "trailer-" + requestCount ] = "true" ;
232
272
return Task . CompletedTask ;
233
273
} ) ;
0 commit comments