0

I've been attempting to get Microsoft.AspNetCore.ResponseCompression 2.1.1 working on a .net core project application that targets the .net full framework 472 to no avail.

I've stripped the project down to it's core leaving only:

        public void ConfigureServices(IServiceCollection services)
        { 
            services.AddResponseCompression(options =>
            {
                options.EnableForHttps = true;

            });
        } 


        public void Configure(IApplicationBuilder app)
        { 
            app.UseResponseCompression();   

            app.UseStaticFiles(); 
        }

I am trying to have the middleware compress a static file.

The request headers:

GET http://localhost:3721/css/Site.css HTTP/1.1
Host: localhost:3721
Connection: keep-alive
Accept: text/css
Accept-Encoding: gzip, deflate, br, *

The response headers:

HTTP/1.1 200 OK
Date: Sat, 03 Nov 2018 01:20:21 GMT
Content-Type: text/css
Server: Kestrel
Last-Modified: Thu, 13 Jul 2017 16:35:14 GMT
Accept-Ranges: bytes
ETag: "1d2fbf600bbcfda"
Vary: Accept-Encoding
Content-Length: 730

Is there anything glaringly wrong with my implementation that would cause the static file response headers to not echo:

content-encoding: gzip (or other)

Is it possible to hook into the method that decides whether to compress the request or not?

Watson
  • 1,385
  • 1
  • 15
  • 36

1 Answers1

1

For your response headers, it already is compressed and indicates the cache (vary) responses with Vary: Accept-Encoding.

Vary

When sent by the server with a value of Accept-Encoding to clients and proxies, the Vary header indicates to the client or proxy that it should cache (vary) responses based on the value of the Accept-Encoding header of the request. The result of returning content with the Vary: Accept-Encoding header is that both compressed and uncompressed responses are cached separately.

You could try differents ways below to see the different results:

  • Chrome : Press Ctrl + F5 to check the response headers.
  • Try PostMan
  • Try Fiddler
Edward
  • 28,296
  • 11
  • 76
  • 121
  • I was using Fiddler. If you uncheck "Remove all encodings" under the rules menu you can then see the Content-Encoding: gzip. Thank you! – Watson Nov 05 '18 at 17:43