@@ -36,7 +36,7 @@ public async Task Request_NoAcceptEncoding_Uncompressed()
36
36
{
37
37
var response = await InvokeMiddleware ( 100 , requestAcceptEncodings : null , responseType : TextPlain ) ;
38
38
39
- CheckResponseNotCompressed ( response , expectedBodyLength : 100 ) ;
39
+ CheckResponseNotCompressed ( response , expectedBodyLength : 100 , sendVaryHeader : false ) ;
40
40
}
41
41
42
42
[ Fact ]
@@ -52,7 +52,7 @@ public async Task Request_AcceptUnknown_NotCompressed()
52
52
{
53
53
var response = await InvokeMiddleware ( 100 , requestAcceptEncodings : new string [ ] { "unknown" } , responseType : TextPlain ) ;
54
54
55
- CheckResponseNotCompressed ( response , expectedBodyLength : 100 ) ;
55
+ CheckResponseNotCompressed ( response , expectedBodyLength : 100 , sendVaryHeader : true ) ;
56
56
}
57
57
58
58
[ Theory ]
@@ -149,7 +149,7 @@ public async Task MimeTypes_OtherContentTypes_NoMatch(string contentType)
149
149
150
150
var response = await client . SendAsync ( request ) ;
151
151
152
- CheckResponseNotCompressed ( response , expectedBodyLength : 100 ) ;
152
+ CheckResponseNotCompressed ( response , expectedBodyLength : 100 , sendVaryHeader : false ) ;
153
153
}
154
154
155
155
[ Theory ]
@@ -185,7 +185,7 @@ public async Task NoBody_NotCompressed(string contentType)
185
185
186
186
var response = await client . SendAsync ( request ) ;
187
187
188
- CheckResponseNotCompressed ( response , expectedBodyLength : 0 ) ;
188
+ CheckResponseNotCompressed ( response , expectedBodyLength : 0 , sendVaryHeader : false ) ;
189
189
}
190
190
191
191
[ Fact ]
@@ -201,7 +201,7 @@ public async Task Request_AcceptIdentity_NotCompressed()
201
201
{
202
202
var response = await InvokeMiddleware ( 100 , requestAcceptEncodings : new string [ ] { "identity" } , responseType : TextPlain ) ;
203
203
204
- CheckResponseNotCompressed ( response , expectedBodyLength : 100 ) ;
204
+ CheckResponseNotCompressed ( response , expectedBodyLength : 100 , sendVaryHeader : true ) ;
205
205
}
206
206
207
207
[ Theory ]
@@ -221,15 +221,15 @@ public async Task Request_AcceptWithhigherIdentityQuality_NotCompressed(string[]
221
221
{
222
222
var response = await InvokeMiddleware ( 100 , requestAcceptEncodings : acceptEncodings , responseType : TextPlain ) ;
223
223
224
- CheckResponseNotCompressed ( response , expectedBodyLength : expectedBodyLength ) ;
224
+ CheckResponseNotCompressed ( response , expectedBodyLength : expectedBodyLength , sendVaryHeader : true ) ;
225
225
}
226
226
227
227
[ Fact ]
228
228
public async Task Response_UnknownMimeType_NotCompressed ( )
229
229
{
230
230
var response = await InvokeMiddleware ( 100 , requestAcceptEncodings : new string [ ] { "gzip" } , responseType : "text/custom" ) ;
231
231
232
- CheckResponseNotCompressed ( response , expectedBodyLength : 100 ) ;
232
+ CheckResponseNotCompressed ( response , expectedBodyLength : 100 , sendVaryHeader : false ) ;
233
233
}
234
234
235
235
[ Fact ]
@@ -240,7 +240,7 @@ public async Task Response_WithContentRange_NotCompressed()
240
240
r . Headers [ HeaderNames . ContentRange ] = "1-2/*" ;
241
241
} ) ;
242
242
243
- CheckResponseNotCompressed ( response , expectedBodyLength : 50 ) ;
243
+ CheckResponseNotCompressed ( response , expectedBodyLength : 50 , sendVaryHeader : false ) ;
244
244
}
245
245
246
246
[ Fact ]
@@ -662,7 +662,7 @@ public async Task SendFileAsync_DifferentContentType_NotBypassed()
662
662
663
663
var response = await client . SendAsync ( request ) ;
664
664
665
- CheckResponseNotCompressed ( response , expectedBodyLength : 1024 ) ;
665
+ CheckResponseNotCompressed ( response , expectedBodyLength : 1024 , sendVaryHeader : false ) ;
666
666
667
667
Assert . True ( fakeSendFile . Invoked ) ;
668
668
}
@@ -808,9 +808,25 @@ private void CheckResponseCompressed(HttpResponseMessage response, int expectedB
808
808
Assert . Equal ( expectedBodyLength , response . Content . Headers . ContentLength ) ;
809
809
}
810
810
811
- private void CheckResponseNotCompressed ( HttpResponseMessage response , int expectedBodyLength )
811
+ private void CheckResponseNotCompressed ( HttpResponseMessage response , int expectedBodyLength , bool sendVaryHeader )
812
812
{
813
- Assert . False ( response . Headers . Contains ( HeaderNames . Vary ) ) ;
813
+ if ( sendVaryHeader )
814
+ {
815
+ var containsVaryAcceptEncoding = false ;
816
+ foreach ( var value in response . Headers . GetValues ( HeaderNames . Vary ) )
817
+ {
818
+ if ( value . Contains ( HeaderNames . AcceptEncoding ) )
819
+ {
820
+ containsVaryAcceptEncoding = true ;
821
+ break ;
822
+ }
823
+ }
824
+ Assert . True ( containsVaryAcceptEncoding ) ;
825
+ }
826
+ else
827
+ {
828
+ Assert . False ( response . Headers . Contains ( HeaderNames . Vary ) ) ;
829
+ }
814
830
Assert . NotNull ( response . Headers . GetValues ( HeaderNames . ContentMD5 ) ) ;
815
831
Assert . Empty ( response . Content . Headers . ContentEncoding ) ;
816
832
Assert . Equal ( expectedBodyLength , response . Content . Headers . ContentLength ) ;
0 commit comments