0fa334f3e7
* Create response-compression.md * Update index.md * Update toc.md * Create project.json * Add files via upload * Create project.json * Add files via upload * Update response-compression.md * Update toc.md * Update index.md * Update README.md * Update response-compression.md * Update response-compression.md * Update response-compression.md * Update response-compression.md * Update response-compression.md * Add files via upload * Add files via upload * Update response-compression.md * Update response-compression.md * Update response-compression.md * Update response-compression.md * Update response-compression.md * Update response-compression.md * Update response-compression.md * Update response-compression.md * Update response-compression.md * Update response-compression.md * Create request-uncompressed.png * Add files via upload * Update response-compression.md * Update response-compression.md * Update response-compression.md * Update response-compression.md * Update response-compression.md * Update response-compression.md * Update response-compression.md * Update Startup.cs * Update Startup.cs * Update response-compression.md * Update response-compression.md * Update Startup.cs * Update Startup.cs * Update response-compression.md * Update response-compression.md * Update response-compression.md * Update response-compression.md * Update response-compression.md * Update response-compression.md * Update response-compression.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update response-compression.md * Delete global.json * Delete project.json * Add files via upload * Delete global.json * Delete project.json * Add files via upload * Update response-compression.md * Add files via upload * Delete DefaultsSample.csproj * Delete License.txt * Delete LoremIpsum.cs * Delete README.md * Delete Startup.cs * Delete CustomCompressionProvider.cs * Delete FullSample.csproj * Delete License.txt * Delete LoremIpsum.cs * Delete README.md * Delete Startup.cs * Delete banner.svg * Delete testfile1kb.txt * Update README.md * React to feedback * Alphabetize headers in headers table * Correct files to italics * Update response-compression.md * Minor update * Update Startup.cs * React to feedback * React to feedback * React to feedback * React to feedback * Update ResponseCompressionSample.csproj * Minor update to ms.date * Update LoremIpsum.cs * Update ResponseCompressionSample.csproj * Add files via upload * Update web.config * Update CustomCompressionProvider.cs * Update ResponseCompressionSample.csproj * Add files via upload * Update response-compression.md * Update web.config * Add Nginx reverse-proxy info * Minor update * Indentation fix * Remove ref keyword * React to feedback * custom to mycustomcompression * Additional minor updates * Add link to response-compression doc * Minor update * Revert middleware doc change * Update CustomCompressionProvider.cs * Delete License.txt * Update LoremIpsum.cs * Update Program.cs * Update Startup.cs * Update StartupBasic.cs * React to feedback * Minor update * Update ms.date |
||
---|---|---|
.. | ||
CustomCompressionProvider.cs | ||
LoremIpsum.cs | ||
Program.cs | ||
README.md | ||
ResponseCompressionSample.csproj | ||
Startup.cs | ||
StartupBasic.cs | ||
banner.svg | ||
testfile1kb.txt | ||
web.config |
README.md
Response compression sample application
This sample illustrates the use of ASP.NET Core Response Compression Middleware to compress HTTP responses. The sample demonstrates Gzip and custom compression providers for text and image responses and shows how to add a MIME type for compression.
Examples in this sample
GzipCompressionProvider
text/plain
- / - Lorem Ipsum text file response at 2,044 bytes that will compress to 927 bytes
- /testfile1kb.txt - Text file response at 1,033 bytes that will compress to 47 bytes
- /trickle - Response issued as single characters at 1 second intervals
image/svg+xml
- /banner.svg - A Scalable Vector Graphics (SVG) image response at 9,707 bytes that will compress to 4,459 bytes
CustomCompressionProvider
Shows how to implement a custom compression provider for use with the middleware
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 will be stored in caches for systems that can either accept the compressed or the uncompressed response.
Using the sample
- Make a request using Fiddler, Firebug, or Postman to the application without an
Accept-Encoding
header and note the response payload, response size, and response headers. - Add an
Accept-Encoding: gzip
header and note the compressed response size and response headers. You will see the response size drop and theContent-Encoding: gzip
response header. When you look at the response body for the Lorem Ipsum or testfile1kb.txt response, you will see that the text has been compressed and is unreadable. - Add an
Accept-Encoding: mycustomcompression
header and note the response headers. TheCustomCompressionProvider
is an empty implementation that doesn't actually compress the response, but you can create a custom compression stream wrapper for theCreateStream()
method.