@@ -224,6 +224,153 @@ public async Task MimeTypes_OtherContentTypes_NoMatch(string contentType)
224
224
CheckResponseNotCompressed ( response , expectedBodyLength : 100 , sendVaryHeader : false ) ;
225
225
}
226
226
227
+ [ Theory ]
228
+ [ InlineData ( null , null , "text/plain" , true ) ]
229
+ [ InlineData ( null , new string [ 0 ] , "text/plain" , true ) ]
230
+ [ InlineData ( null , new [ ] { "TEXT/plain" } , "text/plain" , false ) ]
231
+ [ InlineData ( null , new [ ] { "TEXT/*" } , "text/plain" , true ) ]
232
+ [ InlineData ( null , new [ ] { "*/*" } , "text/plain" , true ) ]
233
+
234
+ [ InlineData ( new string [ 0 ] , null , "text/plain" , true ) ]
235
+ [ InlineData ( new string [ 0 ] , new string [ 0 ] , "text/plain" , true ) ]
236
+ [ InlineData ( new string [ 0 ] , new [ ] { "TEXT/plain" } , "text/plain" , false ) ]
237
+ [ InlineData ( new string [ 0 ] , new [ ] { "TEXT/*" } , "text/plain" , true ) ]
238
+ [ InlineData ( new string [ 0 ] , new [ ] { "*/*" } , "text/plain" , true ) ]
239
+
240
+ [ InlineData ( new [ ] { "TEXT/plain" } , null , "text/plain" , true ) ]
241
+ [ InlineData ( new [ ] { "TEXT/plain" } , new string [ 0 ] , "text/plain" , true ) ]
242
+ [ InlineData ( new [ ] { "TEXT/plain" } , new [ ] { "TEXT/plain" } , "text/plain" , false ) ]
243
+ [ InlineData ( new [ ] { "TEXT/plain" } , new [ ] { "TEXT/*" } , "text/plain" , true ) ]
244
+ [ InlineData ( new [ ] { "TEXT/plain" } , new [ ] { "*/*" } , "text/plain" , true ) ]
245
+
246
+ [ InlineData ( new [ ] { "TEXT/*" } , null , "text/plain" , true ) ]
247
+ [ InlineData ( new [ ] { "TEXT/*" } , new string [ 0 ] , "text/plain" , true ) ]
248
+ [ InlineData ( new [ ] { "TEXT/*" } , new [ ] { "TEXT/plain" } , "text/plain" , false ) ]
249
+ [ InlineData ( new [ ] { "TEXT/*" } , new [ ] { "TEXT/*" } , "text/plain" , false ) ]
250
+ [ InlineData ( new [ ] { "TEXT/*" } , new [ ] { "*/*" } , "text/plain" , true ) ]
251
+
252
+ [ InlineData ( new [ ] { "*/*" } , null , "text/plain" , true ) ]
253
+ [ InlineData ( new [ ] { "*/*" } , new string [ 0 ] , "text/plain" , true ) ]
254
+ [ InlineData ( new [ ] { "*/*" } , new [ ] { "TEXT/plain" } , "text/plain" , false ) ]
255
+ [ InlineData ( new [ ] { "*/*" } , new [ ] { "TEXT/*" } , "text/plain" , false ) ]
256
+ [ InlineData ( new [ ] { "*/*" } , new [ ] { "*/*" } , "text/plain" , true ) ]
257
+
258
+ [ InlineData ( null , null , "text/plain2" , false ) ]
259
+ [ InlineData ( null , new string [ 0 ] , "text/plain2" , false ) ]
260
+ [ InlineData ( null , new [ ] { "TEXT/plain" } , "text/plain2" , false ) ]
261
+ [ InlineData ( null , new [ ] { "TEXT/*" } , "text/plain2" , false ) ]
262
+ [ InlineData ( null , new [ ] { "*/*" } , "text/plain2" , false ) ]
263
+
264
+ [ InlineData ( new string [ 0 ] , null , "text/plain2" , false ) ]
265
+ [ InlineData ( new string [ 0 ] , new string [ 0 ] , "text/plain2" , false ) ]
266
+ [ InlineData ( new string [ 0 ] , new [ ] { "TEXT/plain" } , "text/plain2" , false ) ]
267
+ [ InlineData ( new string [ 0 ] , new [ ] { "TEXT/*" } , "text/plain2" , false ) ]
268
+ [ InlineData ( new string [ 0 ] , new [ ] { "*/*" } , "text/plain2" , false ) ]
269
+
270
+ [ InlineData ( new [ ] { "TEXT/plain" } , null , "text/plain2" , false ) ]
271
+ [ InlineData ( new [ ] { "TEXT/plain" } , new string [ 0 ] , "text/plain2" , false ) ]
272
+ [ InlineData ( new [ ] { "TEXT/plain" } , new [ ] { "TEXT/plain" } , "text/plain2" , false ) ]
273
+ [ InlineData ( new [ ] { "TEXT/plain" } , new [ ] { "TEXT/*" } , "text/plain2" , false ) ]
274
+ [ InlineData ( new [ ] { "TEXT/plain" } , new [ ] { "*/*" } , "text/plain2" , false ) ]
275
+
276
+ [ InlineData ( new [ ] { "TEXT/*" } , null , "text/plain2" , true ) ]
277
+ [ InlineData ( new [ ] { "TEXT/*" } , new string [ 0 ] , "text/plain2" , true ) ]
278
+ [ InlineData ( new [ ] { "TEXT/*" } , new [ ] { "TEXT/plain" } , "text/plain2" , true ) ]
279
+ [ InlineData ( new [ ] { "TEXT/*" } , new [ ] { "TEXT/*" } , "text/plain2" , false ) ]
280
+ [ InlineData ( new [ ] { "TEXT/*" } , new [ ] { "*/*" } , "text/plain2" , true ) ]
281
+
282
+ [ InlineData ( new [ ] { "*/*" } , null , "text/plain2" , true ) ]
283
+ [ InlineData ( new [ ] { "*/*" } , new string [ 0 ] , "text/plain2" , true ) ]
284
+ [ InlineData ( new [ ] { "*/*" } , new [ ] { "TEXT/plain" } , "text/plain2" , true ) ]
285
+ [ InlineData ( new [ ] { "*/*" } , new [ ] { "TEXT/*" } , "text/plain2" , false ) ]
286
+ [ InlineData ( new [ ] { "*/*" } , new [ ] { "*/*" } , "text/plain2" , true ) ]
287
+ public async Task MimeTypes_IncludedAndExcluded (
288
+ string [ ] mimeTypes ,
289
+ string [ ] excludedMimeTypes ,
290
+ string mimeType ,
291
+ bool compress
292
+ )
293
+ {
294
+ var builder = new WebHostBuilder ( )
295
+ . ConfigureServices (
296
+ services =>
297
+ services . AddResponseCompression (
298
+ options =>
299
+ {
300
+ options . MimeTypes = mimeTypes ;
301
+ options . ExcludedMimeTypes = excludedMimeTypes ;
302
+ }
303
+ )
304
+ )
305
+ . Configure (
306
+ app =>
307
+ {
308
+ app . UseResponseCompression ( ) ;
309
+ app . Run (
310
+ context =>
311
+ {
312
+ context . Response . Headers [ HeaderNames . ContentMD5 ] = "MD5" ;
313
+ context . Response . ContentType = mimeType ;
314
+ return context . Response . WriteAsync ( new string ( 'a' , 100 ) ) ;
315
+ }
316
+ ) ;
317
+ }
318
+ ) ;
319
+
320
+ var server = new TestServer ( builder ) ;
321
+ var client = server . CreateClient ( ) ;
322
+
323
+ var request = new HttpRequestMessage ( HttpMethod . Get , "" ) ;
324
+ request . Headers . AcceptEncoding . ParseAdd ( "gzip" ) ;
325
+
326
+ var response = await client . SendAsync ( request ) ;
327
+
328
+ if ( compress )
329
+ {
330
+ CheckResponseCompressed ( response , expectedBodyLength : 24 , expectedEncoding : "gzip" ) ;
331
+ }
332
+ else
333
+ {
334
+ CheckResponseNotCompressed ( response , expectedBodyLength : 100 , sendVaryHeader : false ) ;
335
+ }
336
+ }
337
+
338
+ [ Fact ]
339
+ public async Task NoIncludedMimeTypes_UseDefaults ( )
340
+ {
341
+ var builder = new WebHostBuilder ( )
342
+ . ConfigureServices (
343
+ services =>
344
+ services . AddResponseCompression (
345
+ options => options . ExcludedMimeTypes = new [ ] { "text/*" }
346
+ )
347
+ )
348
+ . Configure (
349
+ app =>
350
+ {
351
+ app . UseResponseCompression ( ) ;
352
+ app . Run (
353
+ context =>
354
+ {
355
+ context . Response . Headers [ HeaderNames . ContentMD5 ] = "MD5" ;
356
+ context . Response . ContentType = TextPlain ;
357
+ return context . Response . WriteAsync ( new string ( 'a' , 100 ) ) ;
358
+ }
359
+ ) ;
360
+ }
361
+ ) ;
362
+
363
+ var server = new TestServer ( builder ) ;
364
+ var client = server . CreateClient ( ) ;
365
+
366
+ var request = new HttpRequestMessage ( HttpMethod . Get , "" ) ;
367
+ request . Headers . AcceptEncoding . ParseAdd ( "gzip" ) ;
368
+
369
+ var response = await client . SendAsync ( request ) ;
370
+
371
+ CheckResponseCompressed ( response , expectedBodyLength : 24 , expectedEncoding : "gzip" ) ;
372
+ }
373
+
227
374
[ Theory ]
228
375
[ InlineData ( "" ) ]
229
376
[ InlineData ( "text/plain" ) ]
0 commit comments