Skip to content

Replace the old InputStreamFactory registries with the new Decoder / Encoder pipeline #660

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

arturobernalg
Copy link
Member

This change swaps out the legacy compression infrastructure for the new decoder / encoder model introduced in 5.6. The codebase now routes all (de)compression through ContentCodecRegistry, uses functional interfaces instead of InputStreamFactory, and updates tests and docs accordingly while preserving existing public classes as deprecated shims. Everything builds and the full test suite passes.

@arturobernalg arturobernalg requested a review from ok2c June 25, 2025 13:11
@@ -32,9 +32,12 @@
* {@link org.apache.hc.core5.http.io.entity.HttpEntityWrapper} responsible for
* handling br Content Coded responses.
*
* @deprecated Use Decoder API
Copy link
Member

Choose a reason for hiding this comment

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

I think it best to use '@link' in '@deprecated' comments. It makes it much easier to follow the bouncing ball 😉

@@ -31,9 +31,10 @@

/**
* Factory for decorated {@link InputStream}s.
*
* @deprecated
Copy link
Member

@garydgregory garydgregory Jun 25, 2025

Choose a reason for hiding this comment

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

The comment with an '@link' is missing, which happens in many places in the PR.

* @since 5.6
*/
@FunctionalInterface
public interface Encoder {
Copy link
Member

Choose a reason for hiding this comment

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

We could reuse or extend UnaryOperator instead of inventing our own.

Copy link
Member Author

Choose a reason for hiding this comment

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

Prefer a dedicated Encoder over UnaryOperator – the name conveys intent and leaves room for HTTP-specific defaults later. Keeps symmetry with Decoder and avoids leaking java.util.function into the public API.

/**
* Custom decoders keyed by {@link ContentCoding}.
*
* @since 5.6
Copy link
Member

Choose a reason for hiding this comment

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

We don't need '@SInCE' tags for private code.

@arturobernalg arturobernalg force-pushed the content-codec-registry branch 2 times, most recently from 3915567 to d0ed410 Compare June 26, 2025 09:10
@arturobernalg
Copy link
Member Author

Added a terse Javadoc note that points users to the new Decoder/Encoder API.

* @since 5.6
*/
@FunctionalInterface
public interface Decoder {
Copy link
Member

Choose a reason for hiding this comment

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

@arturobernalg Should not Decoder be working the same was as Encoder and unwrap HttpEntity?

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 Decoder only swaps the input stream—DecompressingEntity already wraps the HttpEntity—so returning an InputStream keeps the API minimal and avoids duplicating header-handling logic.

Copy link
Member

Choose a reason for hiding this comment

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

@arturobernalg to me it is more important for the API to be logically consistent than saving a few lines of header handling code that will likely get optimized out by the compiler. In my opinion The Encoder / Decoder interfaces should work either with InputStream / OutputStream or with HttpEntity, but not with a mix. Feel free to leave it as is and merge the change-set but I will likely try to normalize the APIs later.

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 please do another pass.

@arturobernalg arturobernalg requested a review from ok2c June 28, 2025 16:50
/**
* Returns the {@link Codec} (or {@code null}).
*/
public static Codec codec(final ContentCoding coding) {
Copy link
Member

Choose a reason for hiding this comment

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

@arturobernalg Here we have a scope violation: a public method exposing a package private class. Either make the method package private or make the class public. It is internal anyway.

* @since 5.6
*/
@FunctionalInterface
public interface Decoder {
Copy link
Member

Choose a reason for hiding this comment

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

@arturobernalg to me it is more important for the API to be logically consistent than saving a few lines of header handling code that will likely get optimized out by the compiler. In my opinion The Encoder / Decoder interfaces should work either with InputStream / OutputStream or with HttpEntity, but not with a mix. Feel free to leave it as is and merge the change-set but I will likely try to normalize the APIs later.

* @throws IOException if the decoding entity cannot be created or an
* underlying I/O error occurs
*/
HttpEntity wrap(HttpEntity src) throws IOException;
Copy link
Member

Choose a reason for hiding this comment

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

@arturobernalg I think this method does not need to throw IOException. At least it does not appear to be thrown anywhere in the existing code.

I also agree with @garydgregory here. I think we could just use standard Function here, but this is a matter of taste so I will not object.

Looks good otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

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

HI @ok2c please do another pass. Now I'm using java functions instead.

Copy link
Member

Choose a reason for hiding this comment

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

HI @ok2c please do another pass. Now I'm using java functions instead.

@arturobernalg Oh, man. I meant something different. I think IOFunction was fine. It makes sense to have a function that throws IOException. What I meant the Decoder and Encoder could be just UnaryOperator or Function as suggested by @garydgregory

@arturobernalg arturobernalg requested a review from ok2c July 5, 2025 12:24
@arturobernalg arturobernalg force-pushed the content-codec-registry branch from c591d1e to 24ac6ca Compare July 5, 2025 12:59
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 I would prefer to have IOFunction restored and Encoder and Decoder replaced but this is more of a matter of taste. You can keep them if you strongly prefer it

@arturobernalg arturobernalg force-pushed the content-codec-registry branch from d3b855c to 8c31bf1 Compare July 7, 2025 11:30
…Encoder pipeline. Adds ContentCodecRegistry, rewrites DecompressingEntity, updates HttpClient internals and tests, deprecates legacy helpers, and keeps backward compatibility.
…ic Encoder/Decoder API, introduce IOFunction and ContentCodecRegistry, update DecompressingEntity and all tests accordingly.
@arturobernalg arturobernalg force-pushed the content-codec-registry branch from 8c31bf1 to 474c669 Compare July 7, 2025 11:32
@arturobernalg
Copy link
Member Author

@arturobernalg I would prefer to have IOFunction restored and Encoder and Decoder replaced but this is more of a matter of taste. You can keep them if you strongly prefer it

@ok2c i just

@arturobernalg I would prefer to have IOFunction restored and Encoder and Decoder replaced but this is more of a matter of taste. You can keep them if you strongly prefer it

HI @ok2c i just implement the UnaryOperator instead. please do another pass.

@arturobernalg arturobernalg requested a review from ok2c July 7, 2025 11:37
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