1

I am struggling with setting up the response compression for an endpoint in .net core 6 API that returns a relatively large sqlite file (>60mb) of type application/vnd.sqlite3.

I adde necessary configuration to Startup.cs class, such as

app.UseResponseCompression();

and

services.AddResponseCompression(options =>
            {
                options.Providers.Add<BrotliCompressionProvider>();
                options.Providers.Add<GzipCompressionProvider>();
                options.MimeTypes =
                    ResponseCompressionDefaults.MimeTypes.Concat(
                    new[] { "application/vnd.sqlite3" });
                options.EnableForHttps = true;
            });

services.Configure<GzipCompressionProviderOptions>(options =>
            {
                options.Level = CompressionLevel.SmallestSize;
            });

response is returned from the controller like this:

return File(dataBytes, "application/vnd.sqlite3");

Even though response contains a header Content-Encoding with gzip/br (depending on request header), the size of a response is essentially the same as without compression.

szachmat
  • 158
  • 13

1 Answers1

0
  1. Did you added compression middleware (app.UseResponseCompression();) in pipeline? If not, place it before controller/map middleware.

  2. You added GzipCompressionProviderOptions but not BrotliCompressionProviderOptions. Test adding it.

  3. Check response headers. if it is compressed you can find related header there.

  4. Not everything can be compressed to reduce size so maybe your content is of this kind. try compressing it manually (use apps or something for example 7zip).

DemiDev
  • 31
  • 6