3
3
4
4
using System . Collections . Generic ;
5
5
using System . Linq ;
6
+ using System . Net . Http . HPack ;
6
7
using Microsoft . AspNetCore . Http ;
7
8
using Microsoft . AspNetCore . Server . Kestrel . Core . Internal . Http ;
8
9
using Microsoft . AspNetCore . Server . Kestrel . Core . Internal . Http2 ;
@@ -21,7 +22,8 @@ public void CanIterateOverResponseHeaders()
21
22
ContentLength = 9 ,
22
23
HeaderAcceptRanges = "AcceptRanges!" ,
23
24
HeaderAge = new StringValues ( new [ ] { "1" , "2" } ) ,
24
- HeaderDate = "Date!"
25
+ HeaderDate = "Date!" ,
26
+ HeaderGrpcEncoding = "Identity!"
25
27
} ;
26
28
responseHeaders . Append ( "Name1" , "Value1" ) ;
27
29
responseHeaders . Append ( "Name2" , "Value2-1" ) ;
@@ -35,15 +37,16 @@ public void CanIterateOverResponseHeaders()
35
37
36
38
Assert . Equal ( new [ ]
37
39
{
38
- new KeyValuePair < string , string > ( "Date" , "Date!" ) ,
39
- new KeyValuePair < string , string > ( "Accept-Ranges" , "AcceptRanges!" ) ,
40
- new KeyValuePair < string , string > ( "Age" , "1" ) ,
41
- new KeyValuePair < string , string > ( "Age" , "2" ) ,
42
- new KeyValuePair < string , string > ( "Content-Length" , "9" ) ,
43
- new KeyValuePair < string , string > ( "Name1" , "Value1" ) ,
44
- new KeyValuePair < string , string > ( "Name2" , "Value2-1" ) ,
45
- new KeyValuePair < string , string > ( "Name2" , "Value2-2" ) ,
46
- new KeyValuePair < string , string > ( "Name3" , "Value3" ) ,
40
+ CreateHeaderResult ( H2StaticTable . Date , "Date" , "Date!" ) ,
41
+ CreateHeaderResult ( - 1 , "Grpc-Encoding" , "Identity!" ) ,
42
+ CreateHeaderResult ( H2StaticTable . AcceptRanges , "Accept-Ranges" , "AcceptRanges!" ) ,
43
+ CreateHeaderResult ( H2StaticTable . Age , "Age" , "1" ) ,
44
+ CreateHeaderResult ( H2StaticTable . Age , "Age" , "2" ) ,
45
+ CreateHeaderResult ( H2StaticTable . ContentLength , "Content-Length" , "9" ) ,
46
+ CreateHeaderResult ( - 1 , "Name1" , "Value1" ) ,
47
+ CreateHeaderResult ( - 1 , "Name2" , "Value2-1" ) ,
48
+ CreateHeaderResult ( - 1 , "Name2" , "Value2-2" ) ,
49
+ CreateHeaderResult ( - 1 , "Name3" , "Value3" ) ,
47
50
} , headers ) ;
48
51
}
49
52
@@ -67,11 +70,11 @@ public void CanIterateOverResponseTrailers()
67
70
68
71
Assert . Equal ( new [ ]
69
72
{
70
- new KeyValuePair < string , string > ( "ETag" , "ETag!" ) ,
71
- new KeyValuePair < string , string > ( "Name1" , "Value1" ) ,
72
- new KeyValuePair < string , string > ( "Name2" , "Value2-1" ) ,
73
- new KeyValuePair < string , string > ( "Name2" , "Value2-2" ) ,
74
- new KeyValuePair < string , string > ( "Name3" , "Value3" ) ,
73
+ CreateHeaderResult ( H2StaticTable . ETag , "ETag" , "ETag!" ) ,
74
+ CreateHeaderResult ( - 1 , "Name1" , "Value1" ) ,
75
+ CreateHeaderResult ( - 1 , "Name2" , "Value2-1" ) ,
76
+ CreateHeaderResult ( - 1 , "Name2" , "Value2-2" ) ,
77
+ CreateHeaderResult ( - 1 , "Name3" , "Value3" ) ,
75
78
} , headers ) ;
76
79
}
77
80
@@ -89,14 +92,17 @@ public void Initialize_ChangeHeadersSource_EnumeratorUsesNewSource()
89
92
Assert . True ( e . MoveNext ( ) ) ;
90
93
Assert . Equal ( "Name1" , e . Current . Key ) ;
91
94
Assert . Equal ( "Value1" , e . Current . Value ) ;
95
+ Assert . Equal ( - 1 , e . HPackStaticTableId ) ;
92
96
93
97
Assert . True ( e . MoveNext ( ) ) ;
94
98
Assert . Equal ( "Name2" , e . Current . Key ) ;
95
99
Assert . Equal ( "Value2-1" , e . Current . Value ) ;
100
+ Assert . Equal ( - 1 , e . HPackStaticTableId ) ;
96
101
97
102
Assert . True ( e . MoveNext ( ) ) ;
98
103
Assert . Equal ( "Name2" , e . Current . Key ) ;
99
104
Assert . Equal ( "Value2-2" , e . Current . Value ) ;
105
+ Assert . Equal ( - 1 , e . HPackStaticTableId ) ;
100
106
101
107
var responseTrailers = new HttpResponseTrailers
102
108
{
@@ -111,30 +117,39 @@ public void Initialize_ChangeHeadersSource_EnumeratorUsesNewSource()
111
117
Assert . True ( e . MoveNext ( ) ) ;
112
118
Assert . Equal ( "Grpc-Status" , e . Current . Key ) ;
113
119
Assert . Equal ( "1" , e . Current . Value ) ;
120
+ Assert . Equal ( - 1 , e . HPackStaticTableId ) ;
114
121
115
122
Assert . True ( e . MoveNext ( ) ) ;
116
123
Assert . Equal ( "Name1" , e . Current . Key ) ;
117
124
Assert . Equal ( "Value1" , e . Current . Value ) ;
125
+ Assert . Equal ( - 1 , e . HPackStaticTableId ) ;
118
126
119
127
Assert . True ( e . MoveNext ( ) ) ;
120
128
Assert . Equal ( "Name2" , e . Current . Key ) ;
121
129
Assert . Equal ( "Value2-1" , e . Current . Value ) ;
130
+ Assert . Equal ( - 1 , e . HPackStaticTableId ) ;
122
131
123
132
Assert . True ( e . MoveNext ( ) ) ;
124
133
Assert . Equal ( "Name2" , e . Current . Key ) ;
125
134
Assert . Equal ( "Value2-2" , e . Current . Value ) ;
135
+ Assert . Equal ( - 1 , e . HPackStaticTableId ) ;
126
136
127
137
Assert . False ( e . MoveNext ( ) ) ;
128
138
}
129
139
130
- private KeyValuePair < string , string > [ ] GetNormalizedHeaders ( Http2HeadersEnumerator enumerator )
140
+ private ( int HPackStaticTableId , string Name , string Value ) [ ] GetNormalizedHeaders ( Http2HeadersEnumerator enumerator )
131
141
{
132
- var headers = new List < KeyValuePair < string , string > > ( ) ;
142
+ var headers = new List < ( int HPackStaticTableId , string Name , string Value ) > ( ) ;
133
143
while ( enumerator . MoveNext ( ) )
134
144
{
135
- headers . Add ( enumerator . Current ) ;
145
+ headers . Add ( CreateHeaderResult ( enumerator . HPackStaticTableId , enumerator . Current . Key , enumerator . Current . Value ) ) ;
136
146
}
137
147
return headers . ToArray ( ) ;
138
148
}
149
+
150
+ private static ( int HPackStaticTableId , string Key , string Value ) CreateHeaderResult ( int hPackStaticTableId , string key , string value )
151
+ {
152
+ return ( hPackStaticTableId , key , value ) ;
153
+ }
139
154
}
140
155
}
0 commit comments