Skip to content

Commit

Permalink
Fix issuse OpenFeign#1721 Accept-Encoding header is added twice
Browse files Browse the repository at this point in the history
  • Loading branch information
izdt committed Jul 26, 2023
1 parent a84f90c commit 8d3cb65
Show file tree
Hide file tree
Showing 2 changed files with 10 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 @@ -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

0 comments on commit 8d3cb65

Please sign in to comment.