Gzip / Brotli not applied as expected

Vote:
 

After upgrading a client's solution to Optimizely 12 we are trying to apply brotli / gzip compression to api calls on the site, search for instance.

In my startup.cs I've applied the following:

... in ConfigureServices:


...and in Configure:


But when checking the Response Headers for a search api call made, it show nothing about compression whatsoever for Response:

Is there something more I need to do in order for it to be applied?

#298914
Edited, Mar 24, 2023 12:39
Vote:
 

You must enable https 

services.AddResponseCompression(options =>
{
    options.Providers.Add<BrotliCompressionProvider>();
    options.Providers.Add<GzipCompressionProvider>();
    options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[] { "application/json" });
    options.EnableForHttps = true; // 👈🏻👈🏻👈🏻👈🏻
});
#298916
Mar 24, 2023 12:52
Vote:
 

I've added this now. However I still get the same result after restarting the site numerous times to make sure it was applied.

This is one of the calls that I expect to have the compression, are there any issues here?

#298924
Edited, Mar 24, 2023 14:05
Vote:
 

What mimetype does that API respond with?

#298927
Mar 24, 2023 18:44
Vote:
 

Hi sebp

Can you confirm that UseResponseCompression is among the first lines of the Configure method? It has to come before any middleware that can produce a response, because the response is streamed back through a chain of middleware.

PS. "application/json" is already included in the default list. So that is not needed in your configuration.

#298928
Mar 24, 2023 19:11
sebp - Mar 27, 2023 7:31
Thank you Stefan, this was indeed the problem. I tried moving it further up the Configure-method, and that did the trick. I also tried removing the application/json-specification as you suggested and it seems to be working fine without that as well.

Cheers!
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.