Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net core 1.1 UseResponseCompression isn't compressing

I've just upgraded all my .net core packages to asp.net core 1.1. At the same time I thought I'd implement the newly released response compression middleware. However when I look in the browser dev tools (network traffic), I can see that the response is no different in size whether I use compression or not. Additionally there is no response header of type "Content-Encoding" indicating that compression occurred.

Is there anything else I should be doing here to make this work?

My code is as follow:

    public IServiceProvider ConfigureServices(IServiceCollection services)
    {
        services.AddMvc(options => {
            options.CacheProfiles.Add("Never",
                new CacheProfile()
                {
                    Location = ResponseCacheLocation.None,
                    NoStore = true,
                    Duration = 0
                });
        });

        services.AddResponseCompression();

And:

    public void Configure(IApplicationBuilder appBuilder)
    {
        appBuilder.UseResponseCompression();
        appBuilder.UseMvc();
like image 624
Slicc Avatar asked Oct 17 '22 22:10

Slicc


1 Answers

I think you need to specify the compression provider. Try this:

        services.AddResponseCompression(options =>
        {
            options.Providers.Add<GzipCompressionProvider>();
        });

When I do that I see a response that was previously 89kb go to 2kb and the content type and encoding are being set to expected values.

like image 107
Jeff Avatar answered Oct 20 '22 23:10

Jeff