From 63364687d8bbe2af2d0031f745ca3c61144f8b4f Mon Sep 17 00:00:00 2001 From: Zoltan Kornel Torok Date: Fri, 17 Nov 2023 00:21:07 +0100 Subject: [PATCH] NIFI-12383 Replication client should handle accept encoding with lowercase Signed-off-by: Bence Simon This closes #8043 --- .../okhttp/OkHttpReplicationClient.java | 6 +++++- .../okhttp/OkHttpReplicationClientTest.java | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/http/replication/okhttp/OkHttpReplicationClient.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/http/replication/okhttp/OkHttpReplicationClient.java index 3281fa2bf9..36b2b9d583 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/http/replication/okhttp/OkHttpReplicationClient.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/http/replication/okhttp/OkHttpReplicationClient.java @@ -291,7 +291,11 @@ public class OkHttpReplicationClient implements HttpReplicationClient { private boolean isUseGzip(final Map headers) { - final String rawAcceptEncoding = headers.get(HttpHeaders.ACCEPT_ENCODING); + String rawAcceptEncoding = headers.get(HttpHeaders.ACCEPT_ENCODING); + + if (rawAcceptEncoding == null) { + rawAcceptEncoding = headers.get(HttpHeaders.ACCEPT_ENCODING.toLowerCase()); + } if (rawAcceptEncoding == null) { return false; diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/okhttp/OkHttpReplicationClientTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/okhttp/OkHttpReplicationClientTest.java index 17d83de0fe..1fb029049c 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/okhttp/OkHttpReplicationClientTest.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/okhttp/OkHttpReplicationClientTest.java @@ -17,6 +17,7 @@ package org.apache.nifi.cluster.coordination.http.replication.okhttp; +import org.apache.nifi.cluster.coordination.http.replication.PreparedRequest; import org.apache.nifi.security.util.TemporaryKeyStoreBuilder; import org.apache.nifi.security.util.TlsConfiguration; import org.apache.nifi.util.NiFiProperties; @@ -100,6 +101,25 @@ public class OkHttpReplicationClientTest { } } + @Test + void testShouldReadCasInsensitiveAcceptEncoding() { + final Map headers = new HashMap<>(); + headers.put("accept-encoding", "gzip"); + headers.put("Other-Header", "arbitrary value"); + + final NiFiProperties mockProperties = mockNiFiProperties(); + + final OkHttpReplicationClient client = new OkHttpReplicationClient(mockProperties); + + + PreparedRequest request = client.prepareRequest("POST", headers, "TEST"); + + assertEquals(3, request.getHeaders().size()); + assertEquals("gzip", request.getHeaders().get("accept-encoding")); + assertEquals("gzip", request.getHeaders().get("Content-Encoding")); + assertEquals("arbitrary value", request.getHeaders().get("Other-Header")); + } + @Test void testShouldUseKeystorePasswordIfKeyPasswordIsBlank() { final Map propsMap = new HashMap<>();