summaryrefslogtreecommitdiffstats
path: root/vespa-feed-client
diff options
context:
space:
mode:
authorjonmv <venstad@gmail.com>2023-01-09 13:12:31 +0100
committerjonmv <venstad@gmail.com>2023-01-09 13:12:31 +0100
commitfa4353de698150b3381454c869cbd486f3d77020 (patch)
tree7720d478c2ff0df7c62465fdce5e57eeb1ce5449 /vespa-feed-client
parent9a0c96d42f7f2a202d655c431f2d9d3fe8bc1b5e (diff)
Add "auto" compression mode
Diffstat (limited to 'vespa-feed-client')
-rw-r--r--vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/ApacheCluster.java4
-rw-r--r--vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/FeedClientBuilderImpl.java3
-rw-r--r--vespa-feed-client/src/test/java/ai/vespa/feed/client/impl/ApacheClusterTest.java2
3 files changed, 6 insertions, 3 deletions
diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/ApacheCluster.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/ApacheCluster.java
index 639aebf7c46..19f3ccf7a83 100644
--- a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/ApacheCluster.java
+++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/ApacheCluster.java
@@ -36,6 +36,8 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.GZIPOutputStream;
+import static ai.vespa.feed.client.FeedClientBuilder.Compression.auto;
+import static ai.vespa.feed.client.FeedClientBuilder.Compression.gzip;
import static org.apache.hc.core5.http.ssl.TlsCiphers.excludeH2Blacklisted;
import static org.apache.hc.core5.http.ssl.TlsCiphers.excludeWeak;
@@ -89,7 +91,7 @@ class ApacheCluster implements Cluster {
wrapped.headers().forEach((name, value) -> request.setHeader(name, value.get()));
if (wrapped.body() != null) {
byte[] body = wrapped.body();
- if (compression == Compression.gzip || compression == null && body.length > 512) {
+ if (compression == gzip || compression == auto && body.length > 512) {
request.setHeader(gzipEncodingHeader);
body = gzipped(body);
}
diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/FeedClientBuilderImpl.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/FeedClientBuilderImpl.java
index b364ba953eb..e5bfffbf24d 100644
--- a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/FeedClientBuilderImpl.java
+++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/FeedClientBuilderImpl.java
@@ -21,6 +21,7 @@ import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
+import static ai.vespa.feed.client.FeedClientBuilder.Compression.auto;
import static ai.vespa.feed.client.FeedClientBuilder.Compression.none;
import static java.util.Objects.requireNonNull;
@@ -51,7 +52,7 @@ public class FeedClientBuilderImpl implements FeedClientBuilder {
boolean benchmark = true;
boolean dryrun = false;
boolean speedTest = false;
- Compression compression = null;
+ Compression compression = auto;
URI proxy;
diff --git a/vespa-feed-client/src/test/java/ai/vespa/feed/client/impl/ApacheClusterTest.java b/vespa-feed-client/src/test/java/ai/vespa/feed/client/impl/ApacheClusterTest.java
index 33c043ea271..0c7d94c04ec 100644
--- a/vespa-feed-client/src/test/java/ai/vespa/feed/client/impl/ApacheClusterTest.java
+++ b/vespa-feed-client/src/test/java/ai/vespa/feed/client/impl/ApacheClusterTest.java
@@ -62,7 +62,7 @@ class ApacheClusterTest {
.withHeader("Content-Type", equalTo("application/json; charset=UTF-8"))
.withRequestBody(equalTo("content"));
expected = switch (compression) {
- case none -> expected.withoutHeader("Content-Encoding");
+ case auto, none -> expected.withoutHeader("Content-Encoding");
case gzip -> expected.withHeader("Content-Encoding", equalTo("gzip"));
};
server.verify(1, expected);