Skip to content

Commit

Permalink
Fix issuse #1721 Accept-Encoding header is added twice (#2139)
Browse files Browse the repository at this point in the history
* Fix issuse #1721 Accept-Encoding header is added twice

* format core code
  • Loading branch information
izdt authored Jul 28, 2023
1 parent e2f36f9 commit 6470202
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
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 @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/feign/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down

0 comments on commit 6470202

Please sign in to comment.