[ https://issues.apache.org/jira/browse/HTTPCLIENT-2332?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17866947#comment-17866947 ]
Oleg Kalnichevski commented on HTTPCLIENT-2332: ----------------------------------------------- [~patrickjamesbarry] This issue is essentially a duplicate of HTTPCLIENT-1822. What you need to do is # Build a custom {{AsyncDataConsumer}} that can transparently decompress data and pass it for further processing to another {{AsyncDataConsumer}} # Build a custom {{AsyncDataProducer}} that can transparently compress data produced by another {{AsyncDataProducer}} and commit in to the underlying {{{}DataStreamChannel{}}}. # Build a custom {{ExecResponseInterceptor}} that automatically injects compressing / decompressing data producer / consumer into the request execution pipeline depending on request / response message composition or {{HttpContext}} state. You can use DigestingEntityConsumer [1] and DigestingEntityProducer [2] as a reference and a starting point. Oleg [1] https://github.com/apache/httpcomponents-core/blob/5.2.x/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/DigestingEntityConsumer.java [2] https://github.com/apache/httpcomponents-core/blob/5.2.x/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/DigestingEntityProducer.java > Example of decompressing async response > --------------------------------------- > > Key: HTTPCLIENT-2332 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2332 > Project: HttpComponents HttpClient > Issue Type: Improvement > Components: HttpClient (async) > Affects Versions: 5.3.1 > Reporter: Patrick Barry > Priority: Major > > I have scoured the internet trying to find guidance or an example of how to > properly decompress an entity while using the async client. What is best > practice for wiring in this logic? > > We have a CloseableHttpAsyncClient and we are currently executing a request > like: > {code:java} > Future<Message<HttpResponse, byte[]>> execFuture = > asyncClient.execute(request, > new BasicResponseConsumer<>(new LimitingEntityConsumer(maxSize, > maxTotalWaitTimeForResponse, context)), > null, > context, > new ClientCallback(completableFuture, context) > ); {code} > *LimitingEntityConsumer* [extends BasicAsyncEntityConsumer] keeps track of > how many bytes have been read and if we exceed limit, it throws exception. It > also throws exception if it is taking too long to read/buffer the response. > In the event we have a compressed entity.... what is the best way to handle > this? I have code already to decompress the Entity, but should that logic be > embedded in an overridden method in LimitingEntityConsumer... > > {code:java} > protected abstract T generateContent( * add decompression code here) throws > IOException; {code} > or > register a response interceptor on async client as: > {code:java} > asyncClient.addResponseInterceptorFirst(new Decompressor()) {code} > or > register a AsyncExecChainHandler on async client as: > {code:java} > .addExecInterceptorLast("decompress", new Decompressor()) {code} -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org For additional commands, e-mail: dev-h...@hc.apache.org