You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "arturobernalg (via GitHub)" <gi...@apache.org> on 2025/06/21 18:31:35 UTC
[PR] HTTPCLIENT-2375 Add first-class request-side compression support and pluggable encoders [httpcomponents-client]
arturobernalg opened a new pull request, #657:
URL: https://github.com/apache/httpcomponents-client/pull/657
Adds pluggable request-side compression. You can now call `EntityBuilder.compressed(ContentCoding)` to have any codec discovered at runtime—GZIP remains the default, but `Brotli`, `Zstandard`, `XZ`, and the rest are picked up automatically when Commons Compress and the relevant helper JARs are on the class-path. The change introduces a `ContentEncoderRegistry`, removes duplicate reflection probes via the new `CommonsCompressSupport`, keeps `gzipCompressed()` as a deprecated convenience alias, and ships a tiny `Zstd` round-trip demo plus unit tests. No new mandatory dependencies; everything stays lightweight unless you choose to add more codecs.
--
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: dev-unsubscribe@hc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
Re: [PR] HTTPCLIENT-2375 Add first-class request-side compression support and pluggable encoders [httpcomponents-client]
Posted by "ok2c (via GitHub)" <gi...@apache.org>.
ok2c commented on code in PR #657:
URL: https://github.com/apache/httpcomponents-client/pull/657#discussion_r2160367846
##########
httpclient5/src/main/java/org/apache/hc/client5/http/entity/compress/ContentEncoderRegistry.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.entity.compress;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.Map;
+
+import org.apache.hc.client5.http.entity.DeflateCompressingEntity;
+import org.apache.hc.client5.http.entity.GzipCompressingEntity;
+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.HttpEntity;
+
+@Internal
+@Contract(threading = ThreadingBehavior.STATELESS)
+public final class ContentEncoderRegistry {
Review Comment:
@arturobernalg There should provably be a single registry that can provide wrap / unwrap functions. `InputStreamFactory` should probably be deprecated. This however can be done with another change-set.
##########
httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientServerCompressionExample.java:
##########
@@ -0,0 +1,186 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+
+package org.apache.hc.client5.http.examples;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
+
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpHandler;
+import com.sun.net.httpserver.HttpServer;
+
+import org.apache.commons.compress.compressors.CompressorStreamFactory;
+import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.entity.EntityBuilder;
+import org.apache.hc.client5.http.entity.compress.ContentCoding;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+
+/**
+ * <h2>End-to-end “Zstandard” demo for HttpClient 5.6 +</h2>
+ *
+ * <p>This standalone {@code main()} program shows how the new
+ * {@link org.apache.hc.client5.http.entity.EntityBuilder#compressed
+ * EntityBuilder#compressed(ContentCoding)} API can be used to
+ * transparently <strong>compress</strong> a request entity with
+ * Zstandard (<em>zstd</em>) on the client side and then
+ * <strong>decompress</strong> it on the server side—while the reverse
+ * happens for the response.</p>
+ *
+ * <h3>What the code does</h3>
+ * <ol>
+ * <li>Spins up a tiny in-JVM {@code com.sun.net.httpserver.HttpServer}
+ * bound to an ephemeral port.</li>
+ * <li>The client sends a {@code POST /echo} whose body is compressed
+ * with <em>zstd</em> simply by calling
+ * {@code compressed(ContentCoding.ZSTD)}.</li>
+ * <li>The server handler decodes the request body with Commons Compress
+ * ({@link org.apache.commons.compress.compressors.CompressorStreamFactory}),
+ * echoes the text back, re-encodes it with Zstandard, and sets
+ * {@code Content-Encoding: zstd}.</li>
+ * <li>The client receives the response—HttpClient 5.6+ notices the
+ * header, automatically picks the decoder you registered via
+ * {@link org.apache.hc.client5.http.entity.compress.ContentDecoderRegistry},
+ * and hands the caller the already-decompressed text.</li>
+ * </ol>
+ *
+ * <h3>How to run</h3>
+ * <ul>
+ * <li>Java 8-17 (only standard {@code com.sun.net.httpserver} API used).</li>
+ * <li>Maven dependencies (all <em>compile + runtime</em>):<br>
+ * ─ {@code httpclient5 ≥ 5.6-SNAPSHOT}<br>
+ * ─ {@code commons-compress ≥ 1.21}<br>
+ * ─ {@code com.github.luben:zstd-jni} (automatically pulled by
+ * Commons Compress for the native codec)
+ * </li>
+ * <li>JDK 17+ users: you will see a one-time warning that
+ * {@code zstd-jni} loads native code. Add<br>
+ * {@code --enable-native-access=ALL-UNNAMED} to the VM options
+ * if you want to silence it.</li>
+ * <li>Launch from your IDE or:
+ * <pre>{@code
+ * mvn -q exec:java \
+ * -Dexec.mainClass=org.apache.hc.client5.testing.classic.ZstdRoundTrip
+ * }</pre></li>
+ * </ul>
+ *
+ * <h3>Why Zstandard and not GZIP?</h3>
+ * GZIP support has always been built-in. This demo illustrates the
+ * new <em>pluggable</em> compression framework: as soon as
+ * Commons Compress + the native helper JAR are on the class-path,
+ * HttpClient discovers the codec and you can opt-in at the
+ * <cite>EntityBuilder</cite> call-site—no other code changes needed.
+ *
+ * @since 5.6
+ */
+public final class ClientServerCompressionExample {
+
+ private ClientServerCompressionExample() {
+ }
+
+ public static void main(final String[] args) throws Exception {
+
+ /* ──────────────────────────────────────────────
+ 1. Tiny echo server that understands “br|zstd…”
+ ────────────────────────────────────────────── */
+ final HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
Review Comment:
@arturobernalg Would not it be nicer to use our own `HttpServer` from core here?
--
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: dev-unsubscribe@hc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
Re: [PR] HTTPCLIENT-2375 Add first-class request-side compression support and pluggable encoders [httpcomponents-client]
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #657:
URL: https://github.com/apache/httpcomponents-client/pull/657#discussion_r2161751762
##########
httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientServerCompressionExample.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.examples;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+
+import org.apache.commons.compress.compressors.CompressorException;
+import org.apache.commons.compress.compressors.CompressorStreamFactory;
+import org.apache.hc.client5.http.entity.EntityBuilder;
+import org.apache.hc.client5.http.entity.compress.ContentCoding;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.HttpStatus;
+import org.apache.hc.core5.http.impl.bootstrap.HttpServer;
+import org.apache.hc.core5.http.impl.bootstrap.ServerBootstrap;
+import org.apache.hc.core5.http.io.HttpRequestHandler;
+import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.io.entity.StringEntity;
+import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
+import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.io.CloseMode;
+
+/**
+ * A minimal end-to-end example that shows how the new
+ * {@code EntityBuilder.compressed(ContentCoding)} method (added in 5.6)
+ * can be used to send a request body compressed with Zstandard and to receive
+ * a transparently decompressed response.
+ * <p>
+ * The code spins up an in-process {@link HttpServer} on a random port. The
+ * client builds a simple {@code POST /echo} request whose entity is
+ * compressed by calling
+ * {@code .compressed(ContentCoding.ZSTD)}. The server handler decodes the
+ * incoming body with Apache Commons Compress, echoes the text, re-encodes it
+ * with Zstandard, sets {@code Content-Encoding: zstd} and returns it. On the
+ * way back, HttpClient detects the header, selects the matching decoder that
+ * was registered automatically through {@code ContentDecoderRegistry} and
+ * hands application code a plain {@code String}.
+ * <p>
+ * To run the example you need HttpClient 5.6-SNAPSHOT, Commons Compress
+ * 1.21 or newer and its transitive dependency {@code zstd-jni}. On JDK 17+
+ * the first invocation of the Zstandard codec prints a warning about loading
+ * native code; add {@code --enable-native-access=ALL-UNNAMED} if you prefer a
+ * clean console.
+ *
+ * @since 5.6
+ */
+public final class ClientServerCompressionExample {
+
+ private ClientServerCompressionExample() {
+ }
+
+ public static void main(final String[] args) throws Exception {
+ int port = 8080;
+ if (args.length >= 1) {
+ port = Integer.parseInt(args[0]);
+ }
+ final HttpServer server = ServerBootstrap.bootstrap()
+ .setListenerPort(port)
+ .setCanonicalHostName("localhost")
+ .register("/echo", new EchoHandler())
+ .create();
+ server.start();
+ final int actualPort = server.getLocalPort();
+
+ try (CloseableHttpClient client = HttpClients.createDefault()) {
+ final String requestBody = "Hello Zstandard world!";
+ System.out.println("Request : " + requestBody);
+
+ final ClassicHttpRequest post = ClassicRequestBuilder
+ .post("http://localhost:" + actualPort + "/echo")
+ .setEntity(EntityBuilder.create()
+ .setText(requestBody)
+ .compressed(ContentCoding.ZSTD)
+ .build())
+ .build();
+
+ final String reply = client.execute(
+ post,
+ rsp -> EntityUtils.toString(rsp.getEntity(), StandardCharsets.UTF_8));
+
+ System.out.println("Response: " + reply);
+ } finally {
+ server.close(CloseMode.GRACEFUL);
+ }
+ }
+
+ /**
+ * Simple echo handler that decodes and re-encodes Zstandard bodies.
+ */
+ private static final class EchoHandler implements HttpRequestHandler {
+
+ @Override
+ public void handle(
+ final ClassicHttpRequest request,
+ final ClassicHttpResponse response,
+ final HttpContext context) throws IOException {
+
+ try (InputStream in = new CompressorStreamFactory()
+ .createCompressorInputStream(ContentCoding.ZSTD.token(), request.getEntity().getContent())) {
+
+ final byte[] data = readAll(in);
+ final String text = new String(data, StandardCharsets.UTF_8);
+
+ response.setCode(HttpStatus.SC_OK);
+ response.addHeader("Content-Encoding", ContentCoding.ZSTD.token());
+
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try (final OutputStream zstdOut = new CompressorStreamFactory()
+ .createCompressorOutputStream("zstd", baos)) {
+ zstdOut.write(text.getBytes(StandardCharsets.UTF_8));
+ }
+ response.setEntity(new ByteArrayEntity(baos.toByteArray(), ContentType.TEXT_PLAIN));
+ } catch (final CompressorException ex) {
+ response.setCode(HttpStatus.SC_BAD_REQUEST);
+ response.setEntity(new StringEntity("Compression error: " + ex.getMessage(), StandardCharsets.UTF_8));
Review Comment:
## Information exposure through an error message
[Error information](1) can be exposed to an external user.
[Show more details](https://github.com/apache/httpcomponents-client/security/code-scanning/18)
--
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: dev-unsubscribe@hc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
Re: [PR] HTTPCLIENT-2375 Add first-class request-side compression support and pluggable encoders [httpcomponents-client]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #657:
URL: https://github.com/apache/httpcomponents-client/pull/657#discussion_r2161916299
##########
httpclient5/src/main/java/org/apache/hc/client5/http/entity/compress/ContentEncoderRegistry.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.entity.compress;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.Map;
+
+import org.apache.hc.client5.http.entity.DeflateCompressingEntity;
+import org.apache.hc.client5.http.entity.GzipCompressingEntity;
+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.HttpEntity;
+
+@Internal
+@Contract(threading = ThreadingBehavior.STATELESS)
+public final class ContentEncoderRegistry {
Review Comment:
That sounds like a good plan.
--
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: dev-unsubscribe@hc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
Re: [PR] HTTPCLIENT-2375 Add first-class request-side compression support and pluggable encoders [httpcomponents-client]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #657:
URL: https://github.com/apache/httpcomponents-client/pull/657#discussion_r2160420754
##########
httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientServerCompressionExample.java:
##########
@@ -0,0 +1,186 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+
+package org.apache.hc.client5.http.examples;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
+
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpHandler;
+import com.sun.net.httpserver.HttpServer;
+
+import org.apache.commons.compress.compressors.CompressorStreamFactory;
+import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.entity.EntityBuilder;
+import org.apache.hc.client5.http.entity.compress.ContentCoding;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+
+/**
+ * <h2>End-to-end “Zstandard” demo for HttpClient 5.6 +</h2>
+ *
+ * <p>This standalone {@code main()} program shows how the new
+ * {@link org.apache.hc.client5.http.entity.EntityBuilder#compressed
+ * EntityBuilder#compressed(ContentCoding)} API can be used to
+ * transparently <strong>compress</strong> a request entity with
+ * Zstandard (<em>zstd</em>) on the client side and then
+ * <strong>decompress</strong> it on the server side—while the reverse
+ * happens for the response.</p>
+ *
+ * <h3>What the code does</h3>
+ * <ol>
+ * <li>Spins up a tiny in-JVM {@code com.sun.net.httpserver.HttpServer}
+ * bound to an ephemeral port.</li>
+ * <li>The client sends a {@code POST /echo} whose body is compressed
+ * with <em>zstd</em> simply by calling
+ * {@code compressed(ContentCoding.ZSTD)}.</li>
+ * <li>The server handler decodes the request body with Commons Compress
+ * ({@link org.apache.commons.compress.compressors.CompressorStreamFactory}),
+ * echoes the text back, re-encodes it with Zstandard, and sets
+ * {@code Content-Encoding: zstd}.</li>
+ * <li>The client receives the response—HttpClient 5.6+ notices the
+ * header, automatically picks the decoder you registered via
+ * {@link org.apache.hc.client5.http.entity.compress.ContentDecoderRegistry},
+ * and hands the caller the already-decompressed text.</li>
+ * </ol>
+ *
+ * <h3>How to run</h3>
+ * <ul>
+ * <li>Java 8-17 (only standard {@code com.sun.net.httpserver} API used).</li>
+ * <li>Maven dependencies (all <em>compile + runtime</em>):<br>
+ * ─ {@code httpclient5 ≥ 5.6-SNAPSHOT}<br>
+ * ─ {@code commons-compress ≥ 1.21}<br>
+ * ─ {@code com.github.luben:zstd-jni} (automatically pulled by
+ * Commons Compress for the native codec)
+ * </li>
+ * <li>JDK 17+ users: you will see a one-time warning that
+ * {@code zstd-jni} loads native code. Add<br>
+ * {@code --enable-native-access=ALL-UNNAMED} to the VM options
+ * if you want to silence it.</li>
+ * <li>Launch from your IDE or:
+ * <pre>{@code
+ * mvn -q exec:java \
+ * -Dexec.mainClass=org.apache.hc.client5.testing.classic.ZstdRoundTrip
+ * }</pre></li>
+ * </ul>
+ *
+ * <h3>Why Zstandard and not GZIP?</h3>
+ * GZIP support has always been built-in. This demo illustrates the
+ * new <em>pluggable</em> compression framework: as soon as
+ * Commons Compress + the native helper JAR are on the class-path,
+ * HttpClient discovers the codec and you can opt-in at the
+ * <cite>EntityBuilder</cite> call-site—no other code changes needed.
+ *
+ * @since 5.6
+ */
+public final class ClientServerCompressionExample {
+
+ private ClientServerCompressionExample() {
+ }
+
+ public static void main(final String[] args) throws Exception {
+
+ /* ──────────────────────────────────────────────
+ 1. Tiny echo server that understands “br|zstd…”
+ ────────────────────────────────────────────── */
+ final HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
Review Comment:
Agreed, we have to eat out of our own kitchen here 😉
--
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: dev-unsubscribe@hc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
Re: [PR] HTTPCLIENT-2375 Add first-class request-side compression support and pluggable encoders [httpcomponents-client]
Posted by "arturobernalg (via GitHub)" <gi...@apache.org>.
arturobernalg commented on code in PR #657:
URL: https://github.com/apache/httpcomponents-client/pull/657#discussion_r2161737211
##########
httpclient5/src/main/java/org/apache/hc/client5/http/entity/compress/ContentEncoderRegistry.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.entity.compress;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.Map;
+
+import org.apache.hc.client5.http.entity.DeflateCompressingEntity;
+import org.apache.hc.client5.http.entity.GzipCompressingEntity;
+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.HttpEntity;
+
+@Internal
+@Contract(threading = ThreadingBehavior.STATELESS)
+public final class ContentEncoderRegistry {
Review Comment:
@ok2c I’ll take care of consolidating the encoder / decoder maps into a single registry (and marking `InputStreamFactory` for deprecation) in a follow-up change-set after this PR is merged.
--
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: dev-unsubscribe@hc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
Re: [PR] HTTPCLIENT-2375 Add first-class request-side compression support and pluggable encoders [httpcomponents-client]
Posted by "arturobernalg (via GitHub)" <gi...@apache.org>.
arturobernalg merged PR #657:
URL: https://github.com/apache/httpcomponents-client/pull/657
--
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: dev-unsubscribe@hc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org