Skip to content

Commit

Permalink
NIFI-12383 Replication client should handle accept encoding with lowe…
Browse files Browse the repository at this point in the history
…rcase

Signed-off-by: Bence Simon <[email protected]>
This closes apache#8043
  • Loading branch information
taz1988 authored and simonbence committed Nov 17, 2023
1 parent 9cfdebc commit 6336468
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,11 @@ private Map<String, String> updateHeadersForGzip(final Map<String, String> heade


private boolean isUseGzip(final Map<String, String> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -100,6 +101,25 @@ void testShouldNotReplaceNonZeroContentLengthHeaderOnOtherMethod() {
}
}

@Test
void testShouldReadCasInsensitiveAcceptEncoding() {
final Map<String, String> 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<String, String> propsMap = new HashMap<>();
Expand Down

0 comments on commit 6336468

Please sign in to comment.