GenHTTP icon indicating copy to clipboard operation
GenHTTP copied to clipboard

Add automatic request content decompression

Open thromel opened this issue 1 month ago • 1 comments

Summary

  • Add automatic decompression of incoming request content based on the Content-Encoding header
  • Support for gzip, brotli, zstd, and deflate algorithms
  • Mirrors the existing response compression feature but for incoming request bodies

Features

  • DecompressedContent.Default() pre-configures all supported algorithms
  • Can be enabled via Defaults(decompression: true) or host.Decompression()
  • Custom algorithms can be added via DecompressedContent.Empty().Add()

Usage

// Enable via Defaults
host.Defaults(decompression: true);

// Or enable directly
host.Decompression();

// Or with custom configuration
host.Decompression(DecompressedContent.Default());

New Files

File Purpose
DecompressedContent.cs Public API entry point
IDecompressionAlgorithm.cs Algorithm interface
GzipDecompression.cs Gzip implementation
BrotliDecompression.cs Brotli implementation
ZstdDecompression.cs Zstandard implementation
DeflateDecompression.cs Deflate implementation
DecompressionConcern.cs Request interceptor
DecompressionConcernBuilder.cs Configuration builder
DecompressedRequest.cs Request wrapper with decompressed content

Test plan

  • [x] Test gzip decompression
  • [x] Test brotli decompression
  • [x] Test zstd decompression
  • [x] Test deflate decompression
  • [x] Test passthrough when no Content-Encoding header
  • [x] Test passthrough with unknown encoding
  • [x] Test custom decompression algorithm
  • [x] Test integration with Defaults() method
  • [x] All 16 tests pass (8 test cases x 2 engines)

Fixes #766

thromel avatar Dec 07 '25 19:12 thromel

Thank you very much for your contribution, looks good. Will review and merge the next days.

Kaliumhexacyanoferrat avatar Dec 07 '25 19:12 Kaliumhexacyanoferrat

Thanks for pointing these out. I will address the issues in a different PR. Could you please raise them as an issue?

thromel avatar Dec 10 '25 06:12 thromel

I don't think additional changes are required. It's fine the way it is now.

Kaliumhexacyanoferrat avatar Dec 10 '25 15:12 Kaliumhexacyanoferrat