-
Notifications
You must be signed in to change notification settings - Fork 5
Implement response compression for Testplugin #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,9 +1,13 @@ | ||||||||||||||||||||||||||||||||||
| using AAS.TwinEngine.Plugin.TestPlugin.Infrastructure.Monitoring; | ||||||||||||||||||||||||||||||||||
| using System.IO.Compression; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| using AAS.TwinEngine.Plugin.TestPlugin.Infrastructure.Monitoring; | ||||||||||||||||||||||||||||||||||
| using AAS.TwinEngine.Plugin.TestPlugin.Infrastructure.Providers; | ||||||||||||||||||||||||||||||||||
| using AAS.TwinEngine.Plugin.TestPlugin.ServiceConfiguration; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| using Asp.Versioning; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| using Microsoft.AspNetCore.ResponseCompression; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| namespace AAS.TwinEngine.Plugin.TestPlugin; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| public static class Program | ||||||||||||||||||||||||||||||||||
|
|
@@ -14,6 +18,14 @@ public static class Program | |||||||||||||||||||||||||||||||||
| public static async Task Main(string[] args) | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| var builder = WebApplication.CreateBuilder(args); | ||||||||||||||||||||||||||||||||||
| _ = builder.Services.AddResponseCompression(options => | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| options.EnableForHttps = true; | ||||||||||||||||||||||||||||||||||
| options.Providers.Add<BrotliCompressionProvider>(); | ||||||||||||||||||||||||||||||||||
| options.Providers.Add<GzipCompressionProvider>(); | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
| _ = builder.Services.Configure<BrotliCompressionProviderOptions>(options => options.Level = CompressionLevel.Optimal); | ||||||||||||||||||||||||||||||||||
| _ = builder.Services.Configure<GzipCompressionProviderOptions>(options => options.Level = CompressionLevel.Optimal); | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+21
to
+28
|
||||||||||||||||||||||||||||||||||
| _ = builder.Services.AddResponseCompression(options => | |
| { | |
| options.EnableForHttps = true; | |
| options.Providers.Add<BrotliCompressionProvider>(); | |
| options.Providers.Add<GzipCompressionProvider>(); | |
| }); | |
| _ = builder.Services.Configure<BrotliCompressionProviderOptions>(options => options.Level = CompressionLevel.Optimal); | |
| _ = builder.Services.Configure<GzipCompressionProviderOptions>(options => options.Level = CompressionLevel.Optimal); | |
| builder.Services.AddResponseCompression(options => | |
| { | |
| options.EnableForHttps = true; | |
| options.Providers.Add<BrotliCompressionProvider>(); | |
| options.Providers.Add<GzipCompressionProvider>(); | |
| }); | |
| builder.Services.Configure<BrotliCompressionProviderOptions>(options => options.Level = CompressionLevel.Optimal); | |
| builder.Services.Configure<GzipCompressionProviderOptions>(options => options.Level = CompressionLevel.Optimal); |
Copilot
AI
Mar 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CompressionLevel.Optimal for both Brotli and Gzip can be CPU-expensive and may increase latency under load; for APIs it’s common to use a faster level (or make the level configurable per environment). Consider switching to a faster default and/or reading the level from configuration so it can be tuned without code changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enabling response compression for HTTPS (
EnableForHttps = true) can increase exposure to BREACH-style attacks if any endpoints reflect secrets into responses while an attacker can influence part of the plaintext. Please confirm this service doesn’t return sensitive reflected content (tokens, secrets, CSRF values, etc.), or limit compression to non-sensitive content types/endpoints (and consider making this setting environment-configurable).