Answered by:
Gzip compression doesn't work in Web Api Core

Question
-
User-1350042179 posted
Hi
I applied compression in web api core, but I see the same result with and without compression:
I followed the link:
https://hanssens.com/recipes/enabling-gzip-compression-in-a-dotnet-core-webapi/
Thursday, March 12, 2020 3:21 PM
Answers
-
User-1350042179 posted
Hi
I identify that gzip compression doesn't work in iis express, it only works in IIS onpremise or azure appservice.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, March 13, 2020 3:02 PM
All replies
-
User-474980206 posted
as you don't show the response headers, we can not tell if it worked. check that the gzip accept header was sent, also check the content-encoding response header (should be gzip)
also check that you are not using http/2 which has compression built in and does not use gzip.
Thursday, March 12, 2020 3:51 PM -
User475983607 posted
Please do not make the community guess what your doing. At least share your code, tell us what version of Core you are targeting, explain how you are testing, and the steps to reproduce this behavior..
https://docs.microsoft.com/en-us/aspnet/core/performance/response-compression?view=aspnetcore-3.1
Thursday, March 12, 2020 3:57 PM -
User-1350042179 posted
Hi
This is the response...
I don't see content-encoding: gzip in the response.
Friday, March 13, 2020 12:06 AM -
User-719153870 posted
Hi neoaguil17,
The link article you provied, missed a very important thing for your situation that you have to set EnableForHttps to be true.
public void ConfigureServices(IServiceCollection services) { // Configure Compression level services.Configure<GzipCompressionProviderOptions>(options => options.Level = CompressionLevel.Optimal); // Add Response compression services services.AddResponseCompression(options => { options.EnableForHttps = true; options.Providers.Add<GzipCompressionProvider>(); }); services.AddControllers(); }
Best Regard,
Yang Shen
Friday, March 13, 2020 4:07 AM -
User-1350042179 posted
Hi
I did it but the response has the same time and size.
Friday, March 13, 2020 2:36 PM -
User-1350042179 posted
Hi
I identify that gzip compression doesn't work in iis express, it only works in IIS onpremise or azure appservice.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, March 13, 2020 3:02 PM