Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issuse #1721 Accept-Encoding header is added twice #2139

Merged
merged 3 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/src/main/java/feign/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package feign;

import static feign.Util.CONTENT_ENCODING;
import static feign.Util.ACCEPT_ENCODING;
import static feign.Util.CONTENT_LENGTH;
import static feign.Util.ENCODING_DEFLATE;
import static feign.Util.ENCODING_GZIP;
Expand Down Expand Up @@ -186,6 +187,11 @@ HttpURLConnection convertAndSend(Request request, Options options) throws IOExce
contentLength = Integer.valueOf(value);
connection.addRequestProperty(field, value);
}
}
// Avoid add "Accept-encoding" twice or more when "compression" option is enabled
if (field.equals(ACCEPT_ENCODING)) {
connection.addRequestProperty(field, String.join(", ", request.headers().get(field)));
break;
} else {
connection.addRequestProperty(field, value);
}
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/feign/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public class Util {
* The HTTP Content-Encoding header field name.
*/
public static final String CONTENT_ENCODING = "Content-Encoding";
/**
* The HTTP Accept-Encoding header field name.
*/
public static final String ACCEPT_ENCODING = "Accept-Encoding";
/**
* The HTTP Retry-After header field name.
*/
Expand Down