From ba009a0bd44b1f35d2d428c172ff48532970908e Mon Sep 17 00:00:00 2001 From: iZDT Date: Fri, 28 Jul 2023 15:32:28 +0800 Subject: [PATCH] Fix issuse #1721 Accept-Encoding header is added twice (#2139) * Fix issuse #1721 Accept-Encoding header is added twice * format core code --- core/src/main/java/feign/Client.java | 6 ++++++ core/src/main/java/feign/Util.java | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/core/src/main/java/feign/Client.java b/core/src/main/java/feign/Client.java index 383214d6e..ee0f13039 100644 --- a/core/src/main/java/feign/Client.java +++ b/core/src/main/java/feign/Client.java @@ -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; @@ -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); } diff --git a/core/src/main/java/feign/Util.java b/core/src/main/java/feign/Util.java index 2aa0b2896..cb542d73f 100644 --- a/core/src/main/java/feign/Util.java +++ b/core/src/main/java/feign/Util.java @@ -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. */