PiranhaCMS / piranha.core

Piranha CMS is the friendly editor-focused CMS for .NET that can be used both as an integrated CMS or as a headless API.
http://piranhacms.org
MIT License
1.97k stars 555 forks source link

Brotli Compression Not Working with Piranha CMS #2071

Open vitali-karmanov opened 4 months ago

vitali-karmanov commented 4 months ago

Hello everyone,

Following Microsoft's documentation to enable Brotli compression doesn't seem to work with Piranha CMS. The Content-Encoding header is missing in the response.

image

I wonder if this might be related to issue #1899.

Here is my Program.cs file.

var builder = WebApplication.CreateBuilder(args);

// Enable response compression builder.Services.AddResponseCompression(options => { options.EnableForHttps = true; });

builder.AddPiranha(options => { options.AddRazorRuntimeCompilation = true;

options.UseCms();
options.UseManager();

options.UseFileStorage(naming: Piranha.Local.FileStorageNaming.UniqueFolderNames);
options.UseImageSharp();
options.UseTinyMCE();
options.UseMemoryCache();

var connectionString = builder.Configuration.GetConnectionString("piranha");
options.UseEF<SQLServerDb>(db => db.UseSqlServer(connectionString));
options.UseIdentityWithSeed<IdentitySQLServerDb>(db => db.UseSqlServer(connectionString));

options.Services.AddLogging();

});

var app = builder.Build();

// Use response compression middleware app.UseResponseCompression();

app.UseRouting();

if (app.Environment.IsDevelopment()) { app.UseDeveloperExceptionPage(); }

app.UsePiranha(options => { // Initialize Piranha App.Init(options.Api);

// Build content types
new ContentTypeBuilder(options.Api)
    .AddAssembly(typeof(Program).Assembly)
    .Build()
    .DeleteOrphans();

// Configure Tiny MCE
EditorConfig.FromFile("editorconfig.json");

options.UseManager();
options.UseTinyMCE();
options.UseIdentity();

});

app.Run();

Any guidance or suggestions to resolve this issue would be greatly appreciated.

Thank you!

tidyui commented 3 months ago

The ASP.NET client sdk tools in Piranha is basically just middleware redirecting to ASP.NET, and then it's up to the rendering to do its magic any way it sees fit. In that sense it's strange that Piranha would disable any headers that should be outputted.

tidyui commented 3 months ago

And issue #1899 is regarding adding custom options to the asp.net static file middleware that wasn't added by Piranha by default. This however seems to be more in regards to output compression of the generated HTML. Have you verified that the client is sending the correct Accept-Encoding header to the server?