Skip to content

Add extensible content encoding filter - #14199

Open
arnabnandy7 wants to merge 1 commit into
playframework:mainfrom
arnabnandy7:feature/extensible-content-encoding-filter
Open

arnabnandy7 wants to merge 1 commit into
playframework:mainfrom
arnabnandy7:feature/extensible-content-encoding-filter

Conversation

@arnabnandy7

Copy link
Copy Markdown

Pull Request Checklist

Helpful things

Fixes

Fixes #14073

Purpose

This PR introduces an extensible ContentEncodingFilter for applying custom response content encodings through a Pekko Streams Flow.

The filter provides the response-processing behavior previously implemented directly by GzipFilter, including:

  • Accept-Encoding negotiation
  • Content-Encoding and Vary header handling
  • Strict, streamed, and chunked response handling
  • Preservation of chunk trailers
  • HTTP/1.0 close-delimited response handling
  • Body-size and chunking thresholds
  • A customizable request/result predicate

GzipFilter now delegates this shared behavior to ContentEncodingFilter while preserving its existing constructors, configuration, and public behavior.

Applications can use the new filter with encoding implementations such as Brotli or Zstandard by supplying an encoding name and a factory for the appropriate encoding flow.

Background Context

The response handling in GzipFilter is largely independent of gzip itself. Only the encoding name and the stream transformation are gzip-specific.

Adding Brotli, Zstandard, or another encoding by copying GzipFilter would duplicate negotiation, header management, buffering, and entity-handling logic. Extracting that logic into ContentEncodingFilter provides a reusable extension point while keeping the existing gzip implementation backward compatible.

A flow factory is used instead of a shared flow instance so that each response stream receives a fresh encoder. The existing gzip test coverage continues to exercise the extracted behavior through GzipFilter, with additional focused tests covering custom encodings and transcoding predicates.

The gzip documentation now includes an example showing how to define a Brotli filter using an externally supplied encoding flow.

References

Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
@arnabnandy7
arnabnandy7 force-pushed the feature/extensible-content-encoding-filter branch from 280ff42 to 3235a6c Compare August 15, 2026 14:13
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.

Feature Request: Extensible ContentEncodingFilter for Zstd/Brotli support

1 participant