OpenFeign / feign

Feign makes writing java http clients easier
Apache License 2.0
9.49k stars 1.93k forks source link

Building FeignException can throw llegalCharsetNameException #2540

Closed kubav182 closed 1 month ago

kubav182 commented 1 month ago

WHERE: In this class https://github.com/OpenFeign/feign/blob/master/core/src/main/java/feign/FeignException.java is piece of code:

if (!Charset.isSupported(group)) {
    return null;
}

WHATS WRONG: Some external apis can send header Content-Type: text/xml;charset="utf-8" in response. Problem is with quotes. Method Charset.isSupported throws exception when quotes are part of input string as it checks valid characters. So building FeignException throws exception in this case.

EXPECTED BEHAVIOUR: IF statement does not throw exception. It returns true or null in this case. We can't change external api and preprocess response headers is impossible as they are unmodifiable.

SOLUTION: A. If you want to return true just sanitize String input group and remove for example quotes. Or change regexp to extract it without quotes. group.replaceAll("\"", ""); B. Catch llegalCharsetNameException and return null from IF statement.

kdavisk6 commented 1 month ago

Sounds like you have a good handle on the issue, I recommend submitting a pull request.