Gzip / Brotli not applied as expected


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?

Edited, Mar 24, 2023 12:39

You must enable https 

services.AddResponseCompression(options =>
    options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[] { "application/json" });
    options.EnableForHttps = true; // πŸ‘ˆπŸ»πŸ‘ˆπŸ»πŸ‘ˆπŸ»πŸ‘ˆπŸ»
Mar 24, 2023 12:52

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?

Edited, Mar 24, 2023 14:05

What mimetype does that API respond with?

Mar 24, 2023 18:44

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.

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.

This topic was created over sixΒ months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.