Skip to content

Conversation

@arturobernalg
Copy link
Member

Adds pluggable request-side compression. You can now call EntityBuilder.compressed(ContentCoding) to have any codec discovered at runtime—GZIP remains the default, but Brotli, Zstandard, XZ, and the rest are picked up automatically when Commons Compress and the relevant helper JARs are on the class-path. The change introduces a ContentEncoderRegistry, removes duplicate reflection probes via the new CommonsCompressSupport, keeps gzipCompressed() as a deprecated convenience alias, and ships a tiny Zstd round-trip demo plus unit tests. No new mandatory dependencies; everything stays lightweight unless you choose to add more codecs.

@arturobernalg arturobernalg requested a review from ok2c June 21, 2025 18:31

@Internal
@Contract(threading = ThreadingBehavior.STATELESS)
public final class ContentEncoderRegistry {
Copy link
Member

Choose a reason for hiding this comment

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

@arturobernalg There should provably be a single registry that can provide wrap / unwrap functions. InputStreamFactory should probably be deprecated. This however can be done with another change-set.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ok2c I’ll take care of consolidating the encoder / decoder maps into a single registry (and marking InputStreamFactory for deprecation) in a follow-up change-set after this PR is merged.

Copy link
Member

Choose a reason for hiding this comment

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

That sounds like a good plan.

/* ──────────────────────────────────────────────
1. Tiny echo server that understands “br|zstd…”
────────────────────────────────────────────── */
final HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
Copy link
Member

Choose a reason for hiding this comment

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

@arturobernalg Would not it be nicer to use our own HttpServer from core here?

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, we have to eat out of our own kitchen here 😉

Copy link
Member

@ok2c ok2c left a comment

Choose a reason for hiding this comment

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

@arturobernalg This warning looks legit and probably should be fixed. Otherwise looks good to me.

…pluggable encoders

This change completes the work that began with the decoder registry (HTTPCLIENT-1843) by introducing a symmetric, service-loaded ContentEncoderRegistry and a concise, type-safe API on EntityBuilder.
HttpClient will automatically wrap the chosen entity in the appropriate compressing wrapper, provided that the codec is available on the class-path (via Commons Compress or the built-in GZIP/deflate support).
@arturobernalg arturobernalg merged commit 239948e into apache:master Jun 23, 2025
10 checks passed
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.

3 participants