Skip to content

Commit

Permalink
https://github.com/OpenFeign/feign/issues/2540
Browse files Browse the repository at this point in the history
FeignException does not throw exception during extracting response charset now.

These content types are all valid:
text/html;charset=utf-8
text/html;charset=UTF-8
Text/HTML;Charset="utf-8"
text/html; charset="utf-8"
  • Loading branch information
Jakub Venglar committed Sep 11, 2024
1 parent a695cba commit 1887102
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions core/src/main/java/feign/FeignException.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
Expand All @@ -29,6 +30,7 @@
import java.util.regex.Pattern;
import static feign.Util.*;
import static java.lang.String.format;
import static java.util.regex.Pattern.CASE_INSENSITIVE;

/**
* Origin exception type for all Http Apis.
Expand Down Expand Up @@ -519,14 +521,18 @@ private static Charset getResponseCharset(Map<String, Collection<String>> header
return null;
}

Pattern pattern = Pattern.compile(".*charset=([^\\s|^;]+).*");
Pattern pattern = Pattern.compile(".*charset=\"?([^\\s|^;|^\"]+).*", CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(strings.iterator().next());
if (!matcher.lookingAt()) {
return null;
}

String group = matcher.group(1);
if (!Charset.isSupported(group)) {
try {
if (!Charset.isSupported(group)) {
return null;
}
} catch (IllegalCharsetNameException ex) {
return null;
}
return Charset.forName(group);
Expand Down

0 comments on commit 1887102

Please sign in to comment.