Skip to content

Commit

Permalink
Make Content-Encoding configurable
Browse files Browse the repository at this point in the history
A new configuration property was added to make the Content-Encoding
configurable when using the feign request compression. The default
values are the same as the previous hardcoded values.

Closes issue 1048
  • Loading branch information
AndreTeigler committed Sep 12, 2024
1 parent f9b5e51 commit 2193263
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 209 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2022 the original author or authors.
* Copyright 2013-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,7 +43,7 @@ public class FeignClientEncodingProperties {
/**
* The list of content encodings (applicable encodings depend on the used client).
*/
private String[] contentEncodings = new String[] { HttpEncoding.GZIP_ENCODING, HttpEncoding.DEFLATE_ENCODING };
private String[] contentEncodingTypes = new String[] { HttpEncoding.GZIP_ENCODING, HttpEncoding.DEFLATE_ENCODING };

public String[] getMimeTypes() {
return mimeTypes;
Expand All @@ -61,12 +61,12 @@ public void setMinRequestSize(int minRequestSize) {
this.minRequestSize = minRequestSize;
}

public String[] getContentEncodings() {
return contentEncodings;
public String[] getContentEncodingTypes() {
return contentEncodingTypes;
}

public void setContentEncodings(String[] contentEncodings) {
this.contentEncodings = contentEncodings;
public void setContentEncodingTypes(String[] contentEncodingTypes) {
this.contentEncodingTypes = contentEncodingTypes;
}

@Override
Expand All @@ -79,7 +79,7 @@ public boolean equals(Object o) {
}
FeignClientEncodingProperties that = (FeignClientEncodingProperties) o;
return Arrays.equals(mimeTypes, that.mimeTypes) && Objects.equals(minRequestSize, that.minRequestSize)
&& Arrays.equals(contentEncodings, that.contentEncodings);
&& Arrays.equals(contentEncodingTypes, that.contentEncodingTypes);
}

@Override
Expand All @@ -95,8 +95,8 @@ public String toString() {
.append("minRequestSize=")
.append(minRequestSize)
.append(", ")
.append("contentEncodings=")
.append(Arrays.toString(contentEncodings))
.append("contentEncodingTypes=")
.append(Arrays.toString(contentEncodingTypes))
.append("}")
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.Map;

import feign.RequestTemplate;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
* Enables the HTTP request payload compression by specifying the {@code Content-Encoding}
Expand All @@ -29,6 +31,8 @@
*/
public class FeignContentGzipEncodingInterceptor extends BaseRequestInterceptor {

private static final Log log = LogFactory.getLog(FeignContentGzipEncodingInterceptor.class);

/**
* Creates new instance of {@link FeignContentGzipEncodingInterceptor}.
* @param properties the encoding properties
Expand All @@ -49,10 +53,11 @@ public void apply(RequestTemplate template) {
}

private String[] getContentEncodings() {
if (getProperties().getContentEncodings() != null && getProperties().getContentEncodings().length > 0) {
return getProperties().getContentEncodings();
if (getProperties().getContentEncodingTypes() != null && getProperties().getContentEncodingTypes().length > 0) {
return getProperties().getContentEncodingTypes();
}

log.warn("Invalid content encoding configuration, falling back to default.");
return new String[] { HttpEncoding.GZIP_ENCODING, HttpEncoding.DEFLATE_ENCODING };
}

Expand Down

This file was deleted.

Loading

0 comments on commit 2193263

Please sign in to comment.