Skip to content

Implement Response Compression and Centralize Accept‑Encoding Handling in HTTP Client Configuration #86

Merged
mm-hsh merged 11 commits intodevelopfrom
feature/614-Response-Compression
Mar 30, 2026
Merged

Implement Response Compression and Centralize Accept‑Encoding Handling in HTTP Client Configuration #86
mm-hsh merged 11 commits intodevelopfrom
feature/614-Response-Compression

Conversation

@mm-hsh
Copy link
Copy Markdown
Contributor

@mm-hsh mm-hsh commented Mar 26, 2026

This PR introduces response compression support and simplifies HTTP client configuration by centralizing Accept‑Encoding logic.

Key Changes

  1. Centralized Accept-Encoding Configuration
  • Introduced a static internal list:

  • private static readonly IReadOnlyCollection<string> AcceptEncodings = ["br", "gzip"];

  • All configured HttpClient instances now consistently apply:

    • Accept-Encoding: br
    • Accept-Encoding: gzip
  • Added automatic decompression in HttpClientHandler for:

    • Brotli
    • GZip
  1. Added Response Compression to the API (Program.cs)
  • Enabled built‑in ASP.NET Core response compression middleware.
  • Added providers:
    • BrotliCompressionProvider
    • GzipCompressionProvider

mm-hsh added 2 commits March 26, 2026 10:55
Removed the acceptEncodings parameter from AddHttpClientWithResilience and related calls, using a static internal list ("br", "gzip") instead. This ensures consistent Accept-Encoding headers and simplifies the API. Updated all usages and removed redundant variables.
Copilot AI review requested due to automatic review settings March 26, 2026 09:31
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 26, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Brotli/Gzip response compression to the ASP.NET Core APIs and centralizes outgoing Accept-Encoding + automatic decompression for HttpClient registrations in the DataEngine.

Changes:

  • Enabled ASP.NET Core response compression middleware (Brotli + Gzip) in both DataEngine and TestPlugin.
  • Added a centralized AcceptEncodings list and applied Accept-Encoding headers to resilient HttpClient registrations.
  • Enabled automatic decompression (Brotli/Gzip) on the primary HttpClientHandler for resilient clients.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
source/AAS.TwinEngine.Plugin.TestPlugin/Program.cs Adds response compression services + middleware to the TestPlugin API pipeline.
source/AAS.TwinEngine.DataEngine/Program.cs Adds response compression services + middleware to the DataEngine API pipeline.
source/AAS.TwinEngine.DataEngine/Infrastructure/Http/Extensions/HttpClientRegistrationExtensions.cs Centralizes Accept-Encoding headers and enables automatic decompression for resilient HttpClient registrations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread source/AAS.TwinEngine.DataEngine/Program.cs Outdated
Comment thread source/AAS.TwinEngine.DataEngine/Program.cs Outdated
Comment thread source/AAS.TwinEngine.Plugin.TestPlugin/Program.cs Outdated
@mm-hsh mm-hsh changed the title Implement Response Compression and Centralize Accept‑Encoding Handling in HTTP Client Configuration Implement Response Compression and Centralize Accept‑Encoding Handling in HTTP Client Configuration Mar 26, 2026
@mm-hsh mm-hsh requested a review from Copilot March 26, 2026 10:13
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread source/AAS.TwinEngine.DataEngine/Program.cs Outdated
Comment thread source/AAS.TwinEngine.DataEngine/Program.cs Outdated
mm-hsh added 5 commits March 26, 2026 15:55
Centralize and encapsulate logic for configuring HTTP client Accept-Encoding headers and decompression methods. Introduce helper methods for setting headers and creating handlers, improving code clarity and maintainability. Remove redundant static fields and streamline decompression method selection using LINQ.
Removed explicit inclusion of "application/problem+json" and "application/problem+xml" from the response compression middleware. The middleware now uses only the default MIME types provided by ResponseCompressionDefaults.MimeTypes.
@mm-hsh mm-hsh requested review from mm-asha, mm-kgi and mm-mcn March 27, 2026 07:00
mm-mcn
mm-mcn previously approved these changes Mar 27, 2026
Comment thread source/AAS.TwinEngine.DataEngine/Program.cs Outdated
Comment thread source/AAS.TwinEngine.DataEngine/Program.cs Outdated
Move response compression setup to a dedicated extension method for improved modularity. Simplify HttpClient compression handling by configuring Accept-Encoding headers and automatic decompression inline, and remove redundant helper methods. This results in cleaner and more maintainable server and client compression configuration.
mm-hsh added 2 commits March 30, 2026 12:28
Removed two tests from HttpClientRegistrationExtensionsTests that verified Accept-Encoding headers and automatic decompression for GZip and Brotli in AddHttpClientWithoutResilience. No other changes were made to the class.
Added ResponseCompressionTests using Playwright to verify Data Engine's handling of response compression. Tests cover gzip, identity, and Brotli (br) encodings, ensuring correct Content-Encoding and Vary headers are returned based on client requests. Included a helper method for header extraction.
@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

Test & Coverage Report

Test Results Summary

Metric Count
✅ Passed 1021
❌ Failed 0
⏭️ Skipped 0

View Detailed Test Results


Code Coverage

Unit Tests Coverage

Package Line Rate Branch Rate Complexity Health
AAS.TwinEngine.DataEngine 91% 83% 1504
Summary 91% (2557 / 2807) 83% (1075 / 1295) 1504

Minimum allowed line rate is 80%

Module Tests Coverage

Package Line Rate Branch Rate Complexity Health
AAS.TwinEngine.DataEngine 56% 42% 1504
Summary 56% (1563 / 2807) 42% (540 / 1295) 1504

@mm-hsh mm-hsh merged commit a654f84 into develop Mar 30, 2026
10 checks passed
@mm-hsh mm-hsh deleted the feature/614-Response-Compression branch April 14, 2026 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants