Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-08-05 Thread via GitHub


ok2c commented on PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#issuecomment-3153996645

   Committed as 3fbbd2237216a74cceacf8458655ff19d0120bb4.
   
   @arturobernalg Very good job


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-08-05 Thread via GitHub


ok2c closed pull request #681: HTTPCLIENT-1822: async transparent content 
decompression
URL: https://github.com/apache/httpcomponents-client/pull/681


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-08-04 Thread via GitHub


arturobernalg commented on PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#issuecomment-3151496357

   > @arturobernalg Two things still need to be fixed.
   > 
   > Alternatively I can pull in your change, tweak them a bit and commit it.
   
   @ok2c I just made the missing change. Please feel free to do any tweak that 
you think is need it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-08-04 Thread via GitHub


ok2c commented on code in PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#discussion_r2251978170


##
httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/ContentCompressionAsyncExec.java:
##
@@ -0,0 +1,208 @@
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.hc.client5.http.impl.async;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Locale;
+import java.util.Set;
+import java.util.function.UnaryOperator;
+
+import org.apache.hc.client5.http.async.AsyncExecCallback;
+import org.apache.hc.client5.http.async.AsyncExecChain;
+import org.apache.hc.client5.http.async.AsyncExecChainHandler;
+import org.apache.hc.client5.http.async.methods.InflatingAsyncDataConsumer;
+import org.apache.hc.client5.http.entity.compress.ContentCoding;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.Internal;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.EntityDetails;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HeaderElement;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.config.Lookup;
+import org.apache.hc.core5.http.config.RegistryBuilder;
+import org.apache.hc.core5.http.message.BasicHeaderValueParser;
+import org.apache.hc.core5.http.message.MessageSupport;
+import org.apache.hc.core5.http.message.ParserCursor;
+import org.apache.hc.core5.http.nio.AsyncDataConsumer;
+import org.apache.hc.core5.http.nio.AsyncEntityProducer;
+import org.apache.hc.core5.util.Args;
+
+@Contract(threading = ThreadingBehavior.STATELESS)
+@Internal
+public final class ContentCompressionAsyncExec implements 
AsyncExecChainHandler {
+
+private final Lookup> decoders;
+private final Header acceptEncoding;
+private final boolean ignoreUnknown;
+
+public ContentCompressionAsyncExec(
+final LinkedHashMap> 
decoderMap,
+final boolean ignoreUnknown) {
+
+Args.notEmpty(decoderMap, "Decoder map");
+
+this.acceptEncoding = MessageSupport.headerOfTokens(
+HttpHeaders.ACCEPT_ENCODING, new 
ArrayList<>(decoderMap.keySet()));
+
+final RegistryBuilder> rb = 
RegistryBuilder.create();
+decoderMap.forEach(rb::register);
+this.decoders = rb.build();
+this.ignoreUnknown = ignoreUnknown;
+}
+
+/**
+ * default = DEFLATE only
+ */
+public ContentCompressionAsyncExec() {
+final LinkedHashMap> map = 
new LinkedHashMap<>();
+map.put(ContentCoding.DEFLATE.token(),
+d -> new InflatingAsyncDataConsumer(d, null));
+this.acceptEncoding = MessageSupport.headerOfTokens(
+HttpHeaders.ACCEPT_ENCODING, 
Collections.singletonList(ContentCoding.DEFLATE.token()));
+this.decoders = 
RegistryBuilder.>create()
+.register(ContentCoding.DEFLATE.token(), 
map.get(ContentCoding.DEFLATE.token()))
+.build();
+this.ignoreUnknown = true;
+}
+
+
+@Override
+public void execute(
+final HttpRequest request,
+final AsyncEntityProducer producer,
+final AsyncExecChain.Scope scope,
+final AsyncExecChain chain,
+final AsyncExecCallback cb) throws IOException, HttpException {
+
+final HttpClientContext ctx = scope != null ? scope.clientContext : 
HttpClientContext.create();
+final boolean enabled = 
ctx.getRequestConfigOrDefault().isContentCompressionEna

Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-08-04 Thread via GitHub


ok2c commented on code in PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#discussion_r2251974219


##
httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/ContentCompressionAsyncExec.java:
##
@@ -0,0 +1,208 @@
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.hc.client5.http.impl.async;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Locale;
+import java.util.Set;
+import java.util.function.UnaryOperator;
+
+import org.apache.hc.client5.http.async.AsyncExecCallback;
+import org.apache.hc.client5.http.async.AsyncExecChain;
+import org.apache.hc.client5.http.async.AsyncExecChainHandler;
+import org.apache.hc.client5.http.async.methods.InflatingAsyncDataConsumer;
+import org.apache.hc.client5.http.entity.compress.ContentCoding;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.Internal;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.EntityDetails;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HeaderElement;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.config.Lookup;
+import org.apache.hc.core5.http.config.RegistryBuilder;
+import org.apache.hc.core5.http.message.BasicHeaderValueParser;
+import org.apache.hc.core5.http.message.MessageSupport;
+import org.apache.hc.core5.http.message.ParserCursor;
+import org.apache.hc.core5.http.nio.AsyncDataConsumer;
+import org.apache.hc.core5.http.nio.AsyncEntityProducer;
+import org.apache.hc.core5.util.Args;
+
+@Contract(threading = ThreadingBehavior.STATELESS)
+@Internal
+public final class ContentCompressionAsyncExec implements 
AsyncExecChainHandler {
+
+private final Lookup> decoders;
+private final Header acceptEncoding;
+private final boolean ignoreUnknown;
+
+public ContentCompressionAsyncExec(
+final LinkedHashMap> 
decoderMap,
+final boolean ignoreUnknown) {
+
+Args.notEmpty(decoderMap, "Decoder map");
+
+this.acceptEncoding = MessageSupport.headerOfTokens(
+HttpHeaders.ACCEPT_ENCODING, new 
ArrayList<>(decoderMap.keySet()));
+
+final RegistryBuilder> rb = 
RegistryBuilder.create();
+decoderMap.forEach(rb::register);
+this.decoders = rb.build();
+this.ignoreUnknown = ignoreUnknown;
+}
+
+/**
+ * default = DEFLATE only
+ */
+public ContentCompressionAsyncExec() {
+final LinkedHashMap> map = 
new LinkedHashMap<>();
+map.put(ContentCoding.DEFLATE.token(),
+d -> new InflatingAsyncDataConsumer(d, null));
+this.acceptEncoding = MessageSupport.headerOfTokens(
+HttpHeaders.ACCEPT_ENCODING, 
Collections.singletonList(ContentCoding.DEFLATE.token()));
+this.decoders = 
RegistryBuilder.>create()
+.register(ContentCoding.DEFLATE.token(), 
map.get(ContentCoding.DEFLATE.token()))
+.build();
+this.ignoreUnknown = true;
+}
+
+
+@Override
+public void execute(
+final HttpRequest request,
+final AsyncEntityProducer producer,
+final AsyncExecChain.Scope scope,
+final AsyncExecChain chain,
+final AsyncExecCallback cb) throws IOException, HttpException {
+
+final HttpClientContext ctx = scope != null ? scope.clientContext : 
HttpClientContext.create();
+final boolean enabled = 
ctx.getRequestConfigOrDefault().isContentCompressionEna

Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-08-03 Thread via GitHub


ok2c commented on code in PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#discussion_r2250076282


##
httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/ContentCompressionAsyncExec.java:
##
@@ -0,0 +1,208 @@
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.hc.client5.http.impl.async;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Locale;
+import java.util.Set;
+import java.util.function.UnaryOperator;
+
+import org.apache.hc.client5.http.async.AsyncExecCallback;
+import org.apache.hc.client5.http.async.AsyncExecChain;
+import org.apache.hc.client5.http.async.AsyncExecChainHandler;
+import org.apache.hc.client5.http.async.methods.InflatingAsyncDataConsumer;
+import org.apache.hc.client5.http.entity.compress.ContentCoding;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.Internal;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.EntityDetails;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HeaderElement;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.config.Lookup;
+import org.apache.hc.core5.http.config.RegistryBuilder;
+import org.apache.hc.core5.http.message.BasicHeaderValueParser;
+import org.apache.hc.core5.http.message.MessageSupport;
+import org.apache.hc.core5.http.message.ParserCursor;
+import org.apache.hc.core5.http.nio.AsyncDataConsumer;
+import org.apache.hc.core5.http.nio.AsyncEntityProducer;
+import org.apache.hc.core5.util.Args;
+
+@Contract(threading = ThreadingBehavior.STATELESS)
+@Internal
+public final class ContentCompressionAsyncExec implements 
AsyncExecChainHandler {
+
+private final Lookup> decoders;
+private final Header acceptEncoding;
+private final boolean ignoreUnknown;
+
+public ContentCompressionAsyncExec(
+final LinkedHashMap> 
decoderMap,
+final boolean ignoreUnknown) {
+
+Args.notEmpty(decoderMap, "Decoder map");
+
+this.acceptEncoding = MessageSupport.headerOfTokens(
+HttpHeaders.ACCEPT_ENCODING, new 
ArrayList<>(decoderMap.keySet()));
+
+final RegistryBuilder> rb = 
RegistryBuilder.create();
+decoderMap.forEach(rb::register);
+this.decoders = rb.build();
+this.ignoreUnknown = ignoreUnknown;
+}
+
+/**
+ * default = DEFLATE only
+ */
+public ContentCompressionAsyncExec() {
+final LinkedHashMap> map = 
new LinkedHashMap<>();
+map.put(ContentCoding.DEFLATE.token(),
+d -> new InflatingAsyncDataConsumer(d, null));
+this.acceptEncoding = MessageSupport.headerOfTokens(
+HttpHeaders.ACCEPT_ENCODING, 
Collections.singletonList(ContentCoding.DEFLATE.token()));
+this.decoders = 
RegistryBuilder.>create()
+.register(ContentCoding.DEFLATE.token(), 
map.get(ContentCoding.DEFLATE.token()))
+.build();
+this.ignoreUnknown = true;
+}
+
+
+@Override
+public void execute(
+final HttpRequest request,
+final AsyncEntityProducer producer,
+final AsyncExecChain.Scope scope,
+final AsyncExecChain chain,
+final AsyncExecCallback cb) throws IOException, HttpException {
+
+final HttpClientContext ctx = scope != null ? scope.clientContext : 
HttpClientContext.create();
+final boolean enabled = 
ctx.getRequestConfigOrDefault().isContentCompressionEna

Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-08-03 Thread via GitHub


arturobernalg commented on code in PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#discussion_r2250046172


##
httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/ContentCompressionAsyncExec.java:
##
@@ -0,0 +1,171 @@
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.hc.client5.http.impl.async;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Locale;
+import java.util.function.UnaryOperator;
+
+import org.apache.hc.client5.http.async.AsyncExecCallback;
+import org.apache.hc.client5.http.async.AsyncExecChain;
+import org.apache.hc.client5.http.async.AsyncExecChainHandler;
+import org.apache.hc.client5.http.async.methods.InflatingAsyncDataConsumer;
+import org.apache.hc.client5.http.entity.compress.ContentCoding;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.Internal;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.EntityDetails;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HeaderElement;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.config.Lookup;
+import org.apache.hc.core5.http.config.RegistryBuilder;
+import org.apache.hc.core5.http.message.BasicHeaderValueParser;
+import org.apache.hc.core5.http.message.MessageSupport;
+import org.apache.hc.core5.http.message.ParserCursor;
+import org.apache.hc.core5.http.nio.AsyncDataConsumer;
+import org.apache.hc.core5.http.nio.AsyncEntityProducer;
+import org.apache.hc.core5.util.Args;
+
+@Contract(threading = ThreadingBehavior.STATELESS)
+@Internal
+public final class ContentCompressionAsyncExec implements 
AsyncExecChainHandler {
+
+private final Lookup> decoders;
+private final Header acceptEncoding;
+private final boolean ignoreUnknown;
+
+public ContentCompressionAsyncExec(
+final LinkedHashMap> 
decoderMap,
+final boolean ignoreUnknown) {
+
+Args.notEmpty(decoderMap, "Decoder map");
+
+this.acceptEncoding = MessageSupport.headerOfTokens(
+HttpHeaders.ACCEPT_ENCODING, new 
ArrayList<>(decoderMap.keySet()));
+
+final RegistryBuilder> rb = 
RegistryBuilder.create();
+decoderMap.forEach(rb::register);
+this.decoders = rb.build();
+this.ignoreUnknown = ignoreUnknown;
+}
+
+/**
+ * default = DEFLATE only
+ */
+public ContentCompressionAsyncExec() {
+final LinkedHashMap> map = 
new LinkedHashMap<>();
+map.put(ContentCoding.DEFLATE.token(),
+d -> new InflatingAsyncDataConsumer(d, null));
+this.acceptEncoding = MessageSupport.headerOfTokens(
+HttpHeaders.ACCEPT_ENCODING, 
Collections.singletonList(ContentCoding.DEFLATE.token()));
+this.decoders = 
RegistryBuilder.>create()
+.register(ContentCoding.DEFLATE.token(), 
map.get(ContentCoding.DEFLATE.token()))
+.build();
+this.ignoreUnknown = true;
+}
+
+
+@Override
+public void execute(final HttpRequest request,
+final AsyncEntityProducer producer,
+final AsyncExecChain.Scope scope,
+final AsyncExecChain chain,
+final AsyncExecCallback cb) throws IOException, 
HttpException {
+
+final HttpClientContext ctx = scope != null ? scope.clientContext : 
HttpClientContext.create();
+final boolean enabled = 
ctx.getRequestConfigOrDefault().is

Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-08-03 Thread via GitHub


ok2c commented on code in PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#discussion_r2250022183


##
httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientDeflatePostExample.java:
##
@@ -0,0 +1,110 @@
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.hc.client5.http.examples;
+
+import java.util.concurrent.Future;
+
+import org.apache.hc.client5.http.async.methods.DeflatingAsyncEntityProducer;
+import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
+import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
+import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
+import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.Message;
+import org.apache.hc.core5.http.message.StatusLine;
+import org.apache.hc.core5.http.nio.AsyncEntityProducer;
+import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
+import org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer;
+import org.apache.hc.core5.http.nio.support.BasicRequestProducer;
+import org.apache.hc.core5.http.nio.support.BasicResponseConsumer;
+import org.apache.hc.core5.io.CloseMode;
+
+/**
+ * Simple command-line tool that sends a {@code deflate}-compressed JSON
+ * payload to https://httpbin.org/post";>httpbin.org/post and
+ * prints the echoed response.
+ *
+ * The example demonstrates how to:
+ * 
+ *   Wrap a regular {@link AsyncEntityProducer} with
+ *   {@link DeflatingAsyncEntityProducer}.
+ *   Add the mandatory {@code Content-Encoding} request header.
+ *   Consume the JSON echo using {@link StringAsyncEntityConsumer}.
+ * 
+ *
+ * Swap {@code DeflatingAsyncEntityProducer} for your future
+ * {@code GzipAsyncEntityProducer} once gzip support is added.
+ *
+ * @since 5.6
+ */
+public final class AsyncClientDeflatePostExample {

Review Comment:
   @arturobernalg I do not quite understand how this example differs from 
`AsyncClientDeflateCompressionExample` and what additional value it provides. I 
would drop it.



##
httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/ContentCompressionAsyncExec.java:
##
@@ -0,0 +1,171 @@
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.hc.client5.http.impl.async;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Locale;
+import java.util.function.UnaryOperator;
+
+import org.apa

Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-08-02 Thread via GitHub


arturobernalg commented on code in PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#discussion_r2249528066


##
httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientInflateDecompressionExample.java:
##
@@ -0,0 +1,94 @@
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.hc.client5.http.examples;
+
+import java.util.concurrent.Future;
+
+import org.apache.hc.client5.http.async.methods.InflatingAsyncEntityConsumer;
+import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
+import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
+import org.apache.hc.client5.http.async.methods.SimpleRequestProducer;
+import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
+import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.Message;
+import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
+import org.apache.hc.core5.http.nio.support.BasicResponseConsumer;
+
+/**
+ * Shows how to plug {@link InflatingAsyncEntityConsumer} into the response
+ * pipeline so that a {@code deflate}-encoded body is transparently inflated.
+ *
+ * The example calls https://httpbin.org/deflate";>httpbin,
+ * which deliberately returns a small compressed document.  The consumer
+ * detects the zlib wrapper automatically and hands the caller a plain
+ * UTF-8 string.
+ *
+ * Swap the inner consumer with your own implementation if you need to
+ * stream the inflated bytes directly into a file or parser.
+ *
+ * @since 5.6
+ */
+public class AsyncClientInflateDecompressionExample {
+
+public static void main(final String[] args) throws Exception {
+try (final CloseableHttpAsyncClient client = 
HttpAsyncClients.createDefault()) {
+client.start();
+
+final SimpleHttpRequest request =
+
SimpleRequestBuilder.get("https://httpbin.org/deflate";).build();
+
+final InflatingAsyncEntityConsumer inflating =

Review Comment:
   @ok2c I initially wrapped at the `AsyncEntityConsumer` level, but that broke 
for plain `AsyncDataConsumers` and led to double-wrapping issues. Moving the 
decoder to operate on `AsyncDataConsumer` fixes both problems, works for every 
downstream type, and keeps the implementation fully streaming.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-07-30 Thread via GitHub


ok2c commented on code in PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#discussion_r2243581245


##
httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientInflateDecompressionExample.java:
##
@@ -0,0 +1,94 @@
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.hc.client5.http.examples;
+
+import java.util.concurrent.Future;
+
+import org.apache.hc.client5.http.async.methods.InflatingAsyncEntityConsumer;
+import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
+import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
+import org.apache.hc.client5.http.async.methods.SimpleRequestProducer;
+import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
+import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.Message;
+import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
+import org.apache.hc.core5.http.nio.support.BasicResponseConsumer;
+
+/**
+ * Shows how to plug {@link InflatingAsyncEntityConsumer} into the response
+ * pipeline so that a {@code deflate}-encoded body is transparently inflated.
+ *
+ * The example calls https://httpbin.org/deflate";>httpbin,
+ * which deliberately returns a small compressed document.  The consumer
+ * detects the zlib wrapper automatically and hands the caller a plain
+ * UTF-8 string.
+ *
+ * Swap the inner consumer with your own implementation if you need to
+ * stream the inflated bytes directly into a file or parser.
+ *
+ * @since 5.6
+ */
+public class AsyncClientInflateDecompressionExample {
+
+public static void main(final String[] args) throws Exception {
+try (final CloseableHttpAsyncClient client = 
HttpAsyncClients.createDefault()) {
+client.start();
+
+final SimpleHttpRequest request =
+
SimpleRequestBuilder.get("https://httpbin.org/deflate";).build();
+
+final InflatingAsyncEntityConsumer inflating =

Review Comment:
   @arturobernalg Decompression / inflation should be completely transparent to 
the user, should it not? The purpose of`ContentCompressionAsyncExec` that you 
built is precisely to make the `InflatingAsyncEntityConsumer` wrapping 
automatically.
   
   The problem actually is now the actual entity consumer will get wrapped with 
`InflatingAsyncEntityConsumer` twice.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-07-30 Thread via GitHub


ok2c commented on code in PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#discussion_r2243581245


##
httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientInflateDecompressionExample.java:
##
@@ -0,0 +1,94 @@
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.hc.client5.http.examples;
+
+import java.util.concurrent.Future;
+
+import org.apache.hc.client5.http.async.methods.InflatingAsyncEntityConsumer;
+import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
+import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
+import org.apache.hc.client5.http.async.methods.SimpleRequestProducer;
+import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
+import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.Message;
+import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
+import org.apache.hc.core5.http.nio.support.BasicResponseConsumer;
+
+/**
+ * Shows how to plug {@link InflatingAsyncEntityConsumer} into the response
+ * pipeline so that a {@code deflate}-encoded body is transparently inflated.
+ *
+ * The example calls https://httpbin.org/deflate";>httpbin,
+ * which deliberately returns a small compressed document.  The consumer
+ * detects the zlib wrapper automatically and hands the caller a plain
+ * UTF-8 string.
+ *
+ * Swap the inner consumer with your own implementation if you need to
+ * stream the inflated bytes directly into a file or parser.
+ *
+ * @since 5.6
+ */
+public class AsyncClientInflateDecompressionExample {
+
+public static void main(final String[] args) throws Exception {
+try (final CloseableHttpAsyncClient client = 
HttpAsyncClients.createDefault()) {
+client.start();
+
+final SimpleHttpRequest request =
+
SimpleRequestBuilder.get("https://httpbin.org/deflate";).build();
+
+final InflatingAsyncEntityConsumer inflating =

Review Comment:
   @arturobernalg Decompression / inflation should be completely transparent to 
the user, should it not? The purpose of`ContentCompressionAsyncExec` that you 
built is precisely to make the `new InflatingAsyncEntityConsumer<>(new 
StringAsyncEntityConsumer());` wrapping automatically.
   
   The problem actually is now the actual entity consumer will get wrapped with 
`InflatingAsyncEntityConsumer` twice.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-07-30 Thread via GitHub


arturobernalg commented on code in PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#discussion_r2243545194


##
httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientInflateDecompressionExample.java:
##
@@ -0,0 +1,94 @@
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.hc.client5.http.examples;
+
+import java.util.concurrent.Future;
+
+import org.apache.hc.client5.http.async.methods.InflatingAsyncEntityConsumer;
+import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
+import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
+import org.apache.hc.client5.http.async.methods.SimpleRequestProducer;
+import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
+import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.Message;
+import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
+import org.apache.hc.core5.http.nio.support.BasicResponseConsumer;
+
+/**
+ * Shows how to plug {@link InflatingAsyncEntityConsumer} into the response
+ * pipeline so that a {@code deflate}-encoded body is transparently inflated.
+ *
+ * The example calls https://httpbin.org/deflate";>httpbin,
+ * which deliberately returns a small compressed document.  The consumer
+ * detects the zlib wrapper automatically and hands the caller a plain
+ * UTF-8 string.
+ *
+ * Swap the inner consumer with your own implementation if you need to
+ * stream the inflated bytes directly into a file or parser.
+ *
+ * @since 5.6
+ */
+public class AsyncClientInflateDecompressionExample {
+
+public static void main(final String[] args) throws Exception {
+try (final CloseableHttpAsyncClient client = 
HttpAsyncClients.createDefault()) {
+client.start();
+
+final SimpleHttpRequest request =
+
SimpleRequestBuilder.get("https://httpbin.org/deflate";).build();
+
+final InflatingAsyncEntityConsumer inflating =

Review Comment:
   @ok2c  Shouldn't expect a `AsyncEntityConsumer`  Sorry I'm not 
understands well the issue 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-07-29 Thread via GitHub


ok2c commented on code in PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#discussion_r2240832900


##
httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/DeflatingAsyncEntityProducer.java:
##
@@ -0,0 +1,240 @@
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.hc.client5.http.async.methods;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.zip.Deflater;
+
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.nio.AsyncEntityProducer;
+import org.apache.hc.core5.http.nio.DataStreamChannel;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * {@code AsyncEntityProducer} that streams the output of another producer
+ * through the raw DEFLATE compression algorithm.
+ *
+ * The delegate’s bytes are read in small chunks, compressed with
+ * {@link java.util.zip.Deflater} and written immediately to the HTTP I/O
+ * layer.  Memory use is therefore bounded even for very large request
+ * entities.
+ *
+ * @since 5.6
+ */
+public final class DeflatingAsyncEntityProducer implements AsyncEntityProducer 
{
+
+/**
+ * inbound copy‐buffer
+ */
+private static final int IN_BUF = 8 * 1024;
+/**
+ * outbound staging buffer
+ */
+private static final int OUT_BUF = 8 * 1024;
+
+private final AsyncEntityProducer delegate;
+private final ContentType contentType;
+private final Deflater deflater = new 
Deflater(Deflater.DEFAULT_COMPRESSION, /*nowrap=*/true);
+
+/**
+ * holds compressed bytes not yet sent downstream
+ */
+private final ByteBuffer pending = ByteBuffer.allocate(OUT_BUF);
+private final byte[] in = new byte[IN_BUF];
+
+private final AtomicBoolean delegateEnded = new AtomicBoolean(false);
+private boolean finished = false;
+
+public DeflatingAsyncEntityProducer(final AsyncEntityProducer delegate) {
+this.delegate = Args.notNull(delegate, "delegate");
+this.contentType = ContentType.parse(delegate.getContentType());

Review Comment:
   @arturobernalg What is the point of parsing the content-type just to have to 
convert it back to String again?



##
httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientDeflateCompressionExample.java:
##
@@ -0,0 +1,105 @@
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.hc.client5.http.examples;
+
+import java.util.concurrent.Future;
+
+import org.apache.hc.client5.http.async

Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-07-29 Thread via GitHub


ok2c commented on code in PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#discussion_r2240824434


##
httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/ContentCompressionAsyncExec.java:
##
@@ -0,0 +1,212 @@
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.hc.client5.http.impl.async;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Locale;
+import java.util.Optional;
+import java.util.function.UnaryOperator;
+
+import org.apache.hc.client5.http.async.AsyncExecCallback;
+import org.apache.hc.client5.http.async.AsyncExecChain;
+import org.apache.hc.client5.http.async.AsyncExecChainHandler;
+import org.apache.hc.client5.http.async.methods.InflatingAsyncEntityConsumer;
+import org.apache.hc.client5.http.entity.compress.ContentCoding;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.Internal;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.EntityDetails;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HeaderElement;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.config.Lookup;
+import org.apache.hc.core5.http.config.RegistryBuilder;
+import org.apache.hc.core5.http.message.BasicHeaderValueParser;
+import org.apache.hc.core5.http.message.MessageSupport;
+import org.apache.hc.core5.http.message.ParserCursor;
+import org.apache.hc.core5.http.nio.AsyncDataConsumer;
+import org.apache.hc.core5.http.nio.AsyncEntityConsumer;
+import org.apache.hc.core5.http.nio.AsyncEntityProducer;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * {@code AsyncExecChainHandler} that transparently decompresses HTTP responses
+ * according to the server-supplied {@code Content-Encoding} header.
+ *
+ * The executor wraps the downstream {@link AsyncEntityConsumer} with a
+ * decoder per response.  Supported codings and their factories are
+ * supplied through a {@link LinkedHashMap} whose insertion order is preserved
+ * when generating the {@code Accept-Encoding} request header.
+ *
+ * By default (zero-arg constructor) the handler enables the
+ * {@code deflate} coding and silently ignores unknown codings.
+ * Additional codecs can be registered at runtime via
+ * {@link 
org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder#setContentDecoderMap(java.util.LinkedHashMap)}.
+ *
+ * @since 5.6
+ */
+@Contract(threading = ThreadingBehavior.STATELESS)
+@Internal
+public final class ContentCompressionAsyncExec implements 
AsyncExecChainHandler {
+
+private final Header acceptEncoding;
+private final Lookup>> decoders;
+private final boolean ignoreUnknown;
+
+/**
+ * Creates an executor that advertises and supports exactly the codings
+ * listed in {@code decoderMap}.
+ *
+ * @param decoderMapa {@link LinkedHashMap} whose keys are lower-case
+ *  tokens (e.g. {@code "gzip"}) and whose values are
+ *  functions that wrap a downstream
+ *  {@link AsyncEntityConsumer}
+ *  Note: the map must be a
+ *  {@code LinkedHashMap} so the insertion order—and
+ *  thus the codec preference—is retained.
+ * @param ignoreUnknown if {@code true} unknown server codings are ignored;
+ *  otherwise a {@link HttpException} is thrown.
+ */
+public ContentCompressionAsyncExec(
+final LinkedHash

Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-07-29 Thread via GitHub


arturobernalg commented on code in PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#discussion_r2240488876


##
httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientDeflateCompressionExample.java:
##
@@ -0,0 +1,106 @@
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.hc.client5.http.examples;
+
+import java.util.concurrent.Future;
+
+import org.apache.hc.client5.http.async.methods.DeflatingAsyncEntityProducer;
+import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
+import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
+import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
+import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.Message;
+import org.apache.hc.core5.http.nio.AsyncEntityProducer;
+import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
+import org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer;
+import org.apache.hc.core5.http.nio.support.BasicRequestProducer;
+import org.apache.hc.core5.http.nio.support.BasicResponseConsumer;
+
+/**
+ * Demonstrates how to POST a JSON body compressed on-the-fly with
+ * {@link DeflatingAsyncEntityProducer}.  The program talks to
+ * https://httpbin.org/post";>httpbin, which echoes your request,
+ * making it easy to verify that the {@code Content-Encoding: deflate}
+ * header was honoured.
+ *
+ * Key take-aways:
+ * 
+ *   Wrap any existing {@code AsyncEntityProducer} in the compressor.
+ *   Add the encoding header yourself – HttpClient does not do that for 
you.
+ *   The producer is streaming: huge payloads are never fully 
buffered.
+ * 
+ *
+ * @since 5.6
+ */
+public class AsyncClientDeflateCompressionExample {
+
+public static void main(final String[] args) throws Exception {
+try (final CloseableHttpAsyncClient client = 
HttpAsyncClients.createDefault()) {
+client.start();
+
+final String json = "{\"msg\":\"hello deflated world\"}";
+final AsyncEntityProducer raw =
+new StringAsyncEntityProducer(json, 
ContentType.APPLICATION_JSON);
+
+final AsyncEntityProducer deflated = new 
DeflatingAsyncEntityProducer(raw);
+
+final SimpleHttpRequest request = SimpleRequestBuilder
+.post("https://httpbin.org/post";)
+.addHeader("Content-Encoding", "deflate")

Review Comment:
   @ok2c  you are right. Is not need it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-07-29 Thread via GitHub


ok2c commented on code in PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#discussion_r2239596409


##
httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientDeflateCompressionExample.java:
##
@@ -0,0 +1,106 @@
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.hc.client5.http.examples;
+
+import java.util.concurrent.Future;
+
+import org.apache.hc.client5.http.async.methods.DeflatingAsyncEntityProducer;
+import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
+import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
+import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
+import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.Message;
+import org.apache.hc.core5.http.nio.AsyncEntityProducer;
+import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
+import org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer;
+import org.apache.hc.core5.http.nio.support.BasicRequestProducer;
+import org.apache.hc.core5.http.nio.support.BasicResponseConsumer;
+
+/**
+ * Demonstrates how to POST a JSON body compressed on-the-fly with
+ * {@link DeflatingAsyncEntityProducer}.  The program talks to
+ * https://httpbin.org/post";>httpbin, which echoes your request,
+ * making it easy to verify that the {@code Content-Encoding: deflate}
+ * header was honoured.
+ *
+ * Key take-aways:
+ * 
+ *   Wrap any existing {@code AsyncEntityProducer} in the compressor.
+ *   Add the encoding header yourself – HttpClient does not do that for 
you.
+ *   The producer is streaming: huge payloads are never fully 
buffered.
+ * 
+ *
+ * @since 5.6
+ */
+public class AsyncClientDeflateCompressionExample {
+
+public static void main(final String[] args) throws Exception {
+try (final CloseableHttpAsyncClient client = 
HttpAsyncClients.createDefault()) {
+client.start();
+
+final String json = "{\"msg\":\"hello deflated world\"}";
+final AsyncEntityProducer raw =
+new StringAsyncEntityProducer(json, 
ContentType.APPLICATION_JSON);
+
+final AsyncEntityProducer deflated = new 
DeflatingAsyncEntityProducer(raw);
+
+final SimpleHttpRequest request = SimpleRequestBuilder
+.post("https://httpbin.org/post";)
+.addHeader("Content-Encoding", "deflate")

Review Comment:
   @arturobernalg 
[RequestContent](https://github.com/apache/httpcomponents-core/blob/master/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestContent.java#L136)
 request interceptor should do that automatically. This should not be needed. 
Please double-check.



##
httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientDeflatePostExample.java:
##
@@ -0,0 +1,111 @@
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the Licen

Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-07-25 Thread via GitHub


arturobernalg commented on PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#issuecomment-3117147034

   > build `DeflatingAsyncEntityProducer` and `InflatingAsyncEntityCunsumer` 
using `Deflater` / `Inflater` API directly
   
   @ok2c implemented. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-07-25 Thread via GitHub


ok2c commented on PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#issuecomment-3116846909

   @arturobernalg I guess I failed to properly express myself. I actually 
thought you were going to build `DeflatingAsyncEntityProducer` and 
`InflatingAsyncEntityCunsumer` using `Deflater` / `Inflater` API directly 
without  any of `InputStream` / `OutputStream` code that basically does not 
work well with async transport. I can still see `HttpEntity` / `InputStream` / 
`OutputStream` all over the place. I cannot stop you but i do not find such 
implementations very useful. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-07-24 Thread via GitHub


arturobernalg commented on PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#issuecomment-3113619708

   > @arturobernalg I am not in a position to tell you what to do. At the 
moment I see only `DeflateCompressingAsyncEntityProducer` as promising.
   > 
   > Why does `DeflateDecompressingStringAsyncEntityConsumer` work with 
`String`s only? Could not it work with any arbitrary `EntityConsumer`?
   > 
   > I would focus on these two classes for now and drop the rest.
   
   @ok2c  please do another pass


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-07-24 Thread via GitHub


ok2c commented on PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#issuecomment-3113006910

   @arturobernalg I am not in a position to tell you what to do. At the moment 
I see only `DeflateCompressingAsyncEntityProducer` as promising. 
   
   Why does `DeflateDecompressingStringAsyncEntityConsumer` work with `String`s 
only? Could not it work with any arbitrary `EntityConsumer`? 
   
   I would focus on these two classes for now and drop the rest.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-07-24 Thread via GitHub


garydgregory commented on code in PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#discussion_r2227658081


##
httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/GzipDecompressingStringAsyncEntityConsumer.java:
##
@@ -0,0 +1,334 @@
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.hc.client5.http.async.methods;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.zip.CRC32;
+import java.util.zip.DataFormatException;
+import java.util.zip.Inflater;
+import java.util.zip.ZipException;
+
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.EntityDetails;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.nio.AsyncEntityConsumer;
+import org.apache.hc.core5.http.nio.CapacityChannel;
+
+/**
+ * A GZIP-only {@link AsyncEntityConsumer} that decompresses incrementally 
without buffering the full compressed input.
+ * Parses GZIP header and trailer streaming-style using a state machine. 
Decompressed output is appended to a StringBuilder chunk-by-chunk.
+ * Suitable for modest decompressed payloads.
+ *
+ * @since 5.6
+ */
+public class GzipDecompressingStringAsyncEntityConsumer implements 
AsyncEntityConsumer {
+
+private final StringBuilder resultBuilder = new StringBuilder();
+private FutureCallback callback;
+private List trailers;
+private String result;
+private Inflater inflater;
+private final byte[] decompressBuffer = new byte[8192];
+private ContentType contentType;
+
+private enum GzipState {
+HEADER_MAGIC1, HEADER_MAGIC2, HEADER_METHOD, HEADER_FLAGS, 
HEADER_MTIME1, HEADER_MTIME2, HEADER_MTIME3, HEADER_MTIME4,
+HEADER_XFL, HEADER_OS, HEADER_EXTRA_LEN_LO, HEADER_EXTRA_LEN_HI, 
HEADER_EXTRA, HEADER_NAME, HEADER_COMMENT,
+HEADER_HCRC_LO, HEADER_HCRC_HI, DATA, TRAILER_CRC1, TRAILER_CRC2, 
TRAILER_CRC3, TRAILER_CRC4,
+TRAILER_ISIZE1, TRAILER_ISIZE2, TRAILER_ISIZE3, TRAILER_ISIZE4, DONE, 
ERROR
+}
+
+private GzipState state = GzipState.HEADER_MAGIC1;
+private int flags = 0;

Review Comment:
   I don't think we should initialize instance variables to default values 
(like in C!), it feels like clutter.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-07-24 Thread via GitHub


garydgregory commented on code in PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#discussion_r2227646991


##
httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/CompressingAsyncEntityProducer.java:
##
@@ -0,0 +1,181 @@
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.hc.client5.http.async.methods;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.hc.client5.http.entity.compress.ContentCodecRegistry;
+import org.apache.hc.client5.http.entity.compress.ContentCoding;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
+import org.apache.hc.core5.http.nio.AsyncEntityProducer;
+import org.apache.hc.core5.http.nio.DataStreamChannel;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * Generic {@link AsyncEntityProducer} that compresses the output produced by a
+ * delegate using any codec available via {@link ContentCodecRegistry#encoder}.
+ *
+ * The delegate’s entire payload is buffered once; therefore use this class
+ * only for modest payload sizes.
+ *
+ * @since 5.6
+ */
+public final class CompressingAsyncEntityProducer implements 
AsyncEntityProducer {
+
+private final byte[] compressed;
+private final String codingToken;
+private final ContentType contentType;
+private final AtomicInteger cursor = new AtomicInteger();
+
+public CompressingAsyncEntityProducer(
+final AsyncEntityProducer delegate,
+final String coding) throws IOException {
+
+Args.notNull(delegate, "delegate");
+this.codingToken = Args.notBlank(coding, 
"coding").toLowerCase(Locale.ROOT);
+this.contentType = ContentType.parse(delegate.getContentType());
+
+final ByteArrayOutputStream rawBuf = new ByteArrayOutputStream();
+delegate.produce(new BufferingChannel(rawBuf));
+
+final HttpEntity rawEntity = new ByteArrayEntity(rawBuf.toByteArray(), 
contentType);
+final HttpEntity encodedEnt = encode(rawEntity, codingToken);
+
+final ByteArrayOutputStream encBuf = new ByteArrayOutputStream();
+encodedEnt.writeTo(encBuf);
+this.compressed = encBuf.toByteArray();
+}
+
+@Override
+public boolean isRepeatable() {
+return false;
+}
+
+@Override
+public long getContentLength() {
+return compressed.length;
+}
+
+@Override
+public String getContentType() {
+return contentType.toString();
+}
+
+@Override
+public String getContentEncoding() {
+return codingToken;
+}
+
+@Override
+public boolean isChunked() {
+return false;
+}
+
+@Override
+public int available() {
+return compressed.length - cursor.get();
+}
+
+@Override
+public Set getTrailerNames() {
+return new HashSet<>();
+}
+
+@Override
+public void failed(final Exception ex) {
+}
+
+@Override
+public void releaseResources() {
+}
+
+@Override
+public void produce(final DataStreamChannel ch) throws IOException {
+final int pos = cursor.get();
+if (pos >= compressed.length) {
+ch.endStream(Collections.emptyList());
+return;
+}
+final int chunk = Math.min(8 * 1024, compressed.length - pos);
+ch.write(ByteBuffer.wrap(compressed, pos, chunk));
+cursor.addAndGet(chunk);
+}
+
+private static HttpEntity encode(final HttpEntity src, final 

Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-07-23 Thread via GitHub


arturobernalg commented on PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#issuecomment-3112178383

   > 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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-07-21 Thread via GitHub


ok2c commented on PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#issuecomment-3096126889

   @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. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] HTTPCLIENT-1822: async transparent content decompression [httpcomponents-client]

2025-07-19 Thread via GitHub


ok2c commented on code in PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#discussion_r2217232696


##
httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/DecompressingAsyncEntityConsumer.java:
##
@@ -0,0 +1,102 @@
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.hc.client5.http.async.methods;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.List;
+
+import org.apache.hc.client5.http.entity.compress.ContentCodecRegistry;
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.EntityDetails;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.nio.AsyncEntityConsumer;
+import org.apache.hc.core5.http.nio.CapacityChannel;
+
+/**
+ * An {@link AsyncEntityConsumer} implementation that consumes and decompresses
+ * an HTTP response body to produce a {@link String}, based on the value of the
+ * {@code Content-Encoding} header. Supports all built-in and Commons Compress
+ * codecs registered in {@link ContentCodecRegistry}.
+ *
+ * 
+ * This class buffers the entire response entity content into memory before
+ * applying decompression. Not suitable for large payloads.
+ * 
+ *
+ * @since 5.6
+ */
+public class DecompressingAsyncEntityConsumer implements 
AsyncEntityConsumer {

Review Comment:
   @arturobernalg This class looks completely redundant. I pulled your 
change-set, removed the class, ran the tests and the example and they all 
worked for me. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]