From fdacd85259464c0d8071ade88caf3b5248ef84dc Mon Sep 17 00:00:00 2001 From: Daniel Gee Date: Tue, 26 May 2026 22:45:45 +0100 Subject: [PATCH 1/3] perf: enable response compression (gzip + brotli) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add ASP.NET Core response compression middleware to reduce JSON API payload sizes by ~60-80% for clients that send Accept-Encoding headers. - Register BrotliCompressionProvider and GzipCompressionProvider - Enable compression for HTTPS (safe for API JSON payloads) - Apply UseResponseCompression() middleware early in the pipeline Brotli is preferred when supported (smaller output); Gzip is the fallback for broader client compatibility. No new NuGet packages required — all providers are built into Microsoft.AspNetCore. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- backend/Menu.ApiServiceDefaults/Extensions.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/Menu.ApiServiceDefaults/Extensions.cs b/backend/Menu.ApiServiceDefaults/Extensions.cs index 4bf0a799..e7995814 100644 --- a/backend/Menu.ApiServiceDefaults/Extensions.cs +++ b/backend/Menu.ApiServiceDefaults/Extensions.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.ResponseCompression; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Swashbuckle.AspNetCore.SwaggerGen; @@ -26,6 +27,14 @@ public static TBuilder AddApiServiceDefaults(this TBuilder builder) wh // Problem details builder.Services.AddProblemDetails(); + // Response compression (gzip + brotli for JSON API payloads) + builder.Services.AddResponseCompression(options => + { + options.EnableForHttps = true; + options.Providers.Add(); + options.Providers.Add(); + }); + return builder; } @@ -40,6 +49,7 @@ private static void RegisterDocumentation(SwaggerGenOptions o, string? assemblyN public static WebApplication MapDefaultApiEndpoints(this WebApplication app) { + app.UseResponseCompression(); app.UseExceptionHandler(); From aeb8bce9a54e7599bb396f80c8d7fa16a0a18c18 Mon Sep 17 00:00:00 2001 From: Daniel Gee Date: Fri, 29 May 2026 12:45:06 +0100 Subject: [PATCH 2/3] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- backend/Menu.ApiServiceDefaults/Extensions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/Menu.ApiServiceDefaults/Extensions.cs b/backend/Menu.ApiServiceDefaults/Extensions.cs index e7995814..704c6e99 100644 --- a/backend/Menu.ApiServiceDefaults/Extensions.cs +++ b/backend/Menu.ApiServiceDefaults/Extensions.cs @@ -31,6 +31,7 @@ public static TBuilder AddApiServiceDefaults(this TBuilder builder) wh builder.Services.AddResponseCompression(options => { options.EnableForHttps = true; + options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(["application/problem+json"]); options.Providers.Add(); options.Providers.Add(); }); From 7e488d9339c2c768e725353dc4fa13756b4c3610 Mon Sep 17 00:00:00 2001 From: Daniel Gee Date: Fri, 29 May 2026 22:42:15 +0100 Subject: [PATCH 3/3] Move default API middleware before auth Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- backend/MenuApi/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/MenuApi/Program.cs b/backend/MenuApi/Program.cs index 37a6c706..91373154 100644 --- a/backend/MenuApi/Program.cs +++ b/backend/MenuApi/Program.cs @@ -57,11 +57,11 @@ // Use CORS middleware before authentication/authorization app.UseCors("AllowAll"); +app.MapDefaultApiEndpoints(); + app.UseAuthentication(); app.UseAuthorization(); -app.MapDefaultApiEndpoints(); - // Configure the APIs var api = app.MapGroup("/api") .RequireAuthorization();