diff --git a/core/src/main/java/feign/Client.java b/core/src/main/java/feign/Client.java index 80701dc5f..cb3499bbf 100644 --- a/core/src/main/java/feign/Client.java +++ b/core/src/main/java/feign/Client.java @@ -13,6 +13,7 @@ */ package feign; +import static feign.Util.ACCEPT_ENCODING; import static feign.Util.CONTENT_ENCODING; import static feign.Util.CONTENT_LENGTH; import static feign.Util.ENCODING_DEFLATE; @@ -189,6 +190,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); } diff --git a/core/src/main/java/feign/Util.java b/core/src/main/java/feign/Util.java index bd1cb1e83..502419c6c 100644 --- a/core/src/main/java/feign/Util.java +++ b/core/src/main/java/feign/Util.java @@ -61,6 +61,9 @@ 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. */ public static final String RETRY_AFTER = "Retry-After";