I'm trying to enable response compression using a very simple Asp.Net Core 3.1 application. My current code:
public void ConfigureServices(IServiceCollection services)
{
services.Configure<BrotliCompressionProviderOptions>(options => options.Level = CompressionLevel.Optimal);
services.AddResponseCompression(options =>
{
options.Providers.Add<BrotliCompressionProvider>();
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseResponseCompression();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async context =>
{
var text = File.ReadAllText(@"D:\huge-response.txt");
await context.Response.WriteAsync(text);
});
});
}
In the huge-response.txt file, I have this:
qwer qwert qwert qwert qwert
qwer qwert qwert qwert qwert
qwer qwert qwert qwert qwert
qwer qwert qwert qwert qwert
qwer qwert qwert qwert qwert
qwer qwert qwert qwert qwert
....
repeated a lot times. The file is 626 KB.
Now, let's see what Chrome says about it:
Odd. So let's see in Fiddler. The first request is "normal", the second one is with the header Accept-Encoding: br
I also tried Gzip compression, with basically the same result.
This pretty much the opposite of what I thought would happen. Such a text file should be absurdly compressible, even in the "fastest" configuration. I expect to see less than 1 KB transferred over the network.
What am I doing wrong? Thanks in advance.

