-
Notifications
You must be signed in to change notification settings - Fork 983
HTTPCLIENT-1822: async transparent content decompression #681
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
Conversation
...src/main/java/org/apache/hc/client5/http/async/methods/DecompressingAsyncEntityConsumer.java
Outdated
Show resolved
Hide resolved
ea88226 to
179491f
Compare
62434ab to
8860e93
Compare
|
@arturobernalg I am not sure about this one. I would prefer a proper solution (even if it is GZIP only) without full content buffering or nothing at all. |
@ok2c I've implemented streaming DEFLATE and GZIP compression/decompression without full content buffering, . I'm not sure if this fully aligns with what you requested. |
| if (coding == null) { | ||
| throw new IOException("Unknown coding: " + token); | ||
| } | ||
| final java.util.function.UnaryOperator<HttpEntity> op = ContentCodecRegistry.encoder(coding); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't need to be a fully qualified name.
| } | ||
|
|
||
| private GzipState state = GzipState.HEADER_MAGIC1; | ||
| private int flags = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should initialize instance variables to default values (like in C!), it feels like clutter.
|
@arturobernalg I am not in a position to tell you what to do. At the moment I see only Why does I would focus on these two classes for now and drop the rest. |
@ok2c please do another pass. I'll implement the gzip in another PR> |
|
@arturobernalg I guess I failed to properly express myself. I actually thought you were going to build |
@ok2c implemented. |
ok2c
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturobernalg DeflatingAsyncEntityProducer and InflatingAsyncEntityCunsumer look good.
I would drop CompressingAsyncEntityProducer.
Could you also add an async version of ContentCompressionExec to the request execution pipeline?
42f3668 to
3ab1bc7
Compare
ok2c
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturobernalg Very good otherwise.
.../src/test/java/org/apache/hc/client5/http/examples/AsyncClientDeflateCompressionExample.java
Outdated
Show resolved
Hide resolved
...client5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientDeflatePostExample.java
Outdated
Show resolved
Hide resolved
c2c2e14 to
07a5df6
Compare
...client5/src/main/java/org/apache/hc/client5/http/impl/async/ContentCompressionAsyncExec.java
Outdated
Show resolved
Hide resolved
...nt5/src/main/java/org/apache/hc/client5/http/async/methods/DeflatingAsyncEntityProducer.java
Outdated
Show resolved
Hide resolved
.../src/test/java/org/apache/hc/client5/http/examples/AsyncClientDeflateCompressionExample.java
Outdated
Show resolved
Hide resolved
...rc/test/java/org/apache/hc/client5/http/examples/AsyncClientInflateDecompressionExample.java
Outdated
Show resolved
Hide resolved
3be78ee to
2a74b2d
Compare
ok2c
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturobernalg Almost there.
...client5/src/main/java/org/apache/hc/client5/http/impl/async/ContentCompressionAsyncExec.java
Outdated
Show resolved
Hide resolved
...client5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientDeflatePostExample.java
Outdated
Show resolved
Hide resolved
4a99230 to
123a712
Compare
| } | ||
|
|
||
| String coding = details != null ? details.getContentEncoding() : null; | ||
| if (coding == null && rsp.containsHeader(HttpHeaders.CONTENT_ENCODING)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturobernalg Please use details#getContentEncoding() only. It is the only attribute that is relevant here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturobernalg This stills needs to be fixed.
...client5/src/main/java/org/apache/hc/client5/http/impl/async/ContentCompressionAsyncExec.java
Outdated
Show resolved
Hide resolved
|
|
||
| @Override | ||
| public String getContentType() { | ||
| return original != null ? original.getContentType() : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturobernalg original should never be nulll here. We cannot make an entity if there was none to begin with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturobernalg What about #getTrailerNames?
5c58198 to
c4a5e10
Compare
ok2c
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturobernalg Two things still need to be fixed.
Alternatively I can pull in your change, tweak them a bit and commit it.
…ngAsyncEntityProducer and InflatingAsyncEntityCunsumer using Deflater / Inflater API directly
86333c8 to
5ddd9d4
Compare
@ok2c I just made the missing change. Please feel free to do any tweak that you think is need it. |
|
Committed as 3fbbd22. @arturobernalg Very good job |
This patch fulfils HTTPCLIENT-1822 by delivering transparent (de)compression support in the async pipeline.
DecompressingStringAsyncEntityConsumer – decodes gzip/deflate/brotli/zstd … responses using the codecs in
ContentCodecRegistryand returns the plain body as a String.CompressingAsyncEntityProducer – wraps any outgoing producer and re-encodes its payload with the chosen Content-Encoding, also via ContentCodecRegistry; enables gzip (or other) uploads.
AsyncClientDecompressionExample
shows response-side usage. AsyncClientCompressionExampledemonstrates gzip uploads.With these additions an async client can both receive and send compressed entities without extra boiler-plate.