"
ASP.NET (snapshot 2017) Microsoft documentation and samplesThis sample illustrates the use of ASP.NET Core 1.x Response Compression Middleware to compress HTTP responses for. The sample demonstrates Gzip and custom compression providers for text and image responses and shows how to add a MIME type for compression. For the ASP.NET Core 2.x sample, see Response compression sample application (ASP.NET Core 2.x).
GzipCompressionProvider
text/plain
image/svg+xml
CustomCompressionProvider
When the request includes the Accept-Encoding
header, the sample adds a Vary: Accept-Encoding
header to the response. The Vary
header instructs caches to maintain multiple copies of the response based on alternative values of Accept-Encoding
, so both a compressed (gzip) and uncompressed version are stored in caches for systems that can either accept the compressed or the uncompressed response.
Accept-Encoding
header and note the response payload, response size, and response headers.Accept-Encoding: gzip
header and note the compressed response size and response headers. You see the response size drop, and the Content-Encoding: gzip
response header is included by the sample app. When you look at the response body for the Lorem Ipsum or testfile1kb.txt response, you see that the text is compressed and unreadable.Accept-Encoding: mycustomcompression
header and note the response headers. The CustomCompressionProvider
is an empty implementation that doesn’t actually compress the response, but you can create a custom compression stream wrapper for the CreateStream()
method.