Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ErrorDecoder cannot get the real response's charset #1325

Closed
Linda-pan opened this issue Dec 7, 2020 · 2 comments
Closed

ErrorDecoder cannot get the real response's charset #1325

Linda-pan opened this issue Dec 7, 2020 · 2 comments
Labels
bug Unexpected or incorrect behavior

Comments

@Linda-pan
Copy link
Contributor

Linda-pan commented Dec 7, 2020

Code FeignException in feign-core-10.10.1

 private static Charset getResponseCharset(Map<String, Collection<String>> headers) {

      Collection<String> strings = headers.get("content-type");
      if (strings == null || strings.size() == 0) {
        return null;
      }

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

      String group = matcher.group(1);
      if (!Charset.isSupported(group)) {
        return null;
      }
      return Charset.forName(group);

    }

It seems that matcher.group(1) can only get one charactor, just like "UTF-8" can only get 'U'.

then all charset will become the default value utf-8.

   private static String getBodyAsString(byte[] body, Map<String, Collection<String>> headers) {
      Charset charset = getResponseCharset(headers);
      if (charset == null) {
        charset = Util.UTF_8;
      }
      return getResponseBody(body, charset);
    }

Actually, content-type not only contain "charset", it usually like "application/json;charset=UTF-8".
I suggess that pattern could be ".charset=([^\\s|^;]+)."。
or use “matcher.find()” with "charset=([^\\s|^;]+)"

@kdavisk6 kdavisk6 added the bug Unexpected or incorrect behavior label Dec 21, 2020
@kdavisk6
Copy link
Member

@Linda-pan Feel free to submit a PR to correct this.

@Linda-pan
Copy link
Contributor Author

@kdavisk6 Sorry for my late reply, I will submit a PR as soon as possible.

Linda-pan added a commit to Linda-pan/feign that referenced this issue Dec 30, 2020
Linda-pan added a commit to Linda-pan/feign that referenced this issue Jan 4, 2021
Linda-pan added a commit to Linda-pan/feign that referenced this issue Jan 18, 2021
Linda-pan added a commit to Linda-pan/feign that referenced this issue Jan 18, 2021
Linda-pan added a commit to Linda-pan/feign that referenced this issue Jan 18, 2021
Linda-pan added a commit to Linda-pan/feign that referenced this issue Jan 18, 2021
kdavisk6 added a commit that referenced this issue Mar 7, 2021
)

* Fix bug for FeignException cannot get the correct charset (#1325)

* Add test for (Fix bug for FeignException cannot get the correct charset) (#1325)

* Add more test for (Fix bug for FeignException cannot get the correct charset) (#1325)

* Format test for (Fix bug for FeignException cannot get the correct charset) (#1325)

* Fix bug for FeignException cannot get the correct charset (#1325)

* Add test for (Fix bug for FeignException cannot get the correct charset) (#1325)

* Add more test for (Fix bug for FeignException cannot get the correct charset) (#1325)

* Format test for (Fix bug for FeignException cannot get the correct charset) (#1325)

* Add test for (Fix bug for FeignException cannot get the correct charset) (#1325)

* Add more test for (Fix bug for FeignException cannot get the correct charset) (#1325)

* Format test for (Fix bug for FeignException cannot get the correct charset) (#1325)

* Correcting License Headers for 2021

Co-authored-by: Kevin Davis <kdavisk6@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected or incorrect behavior
Projects
None yet
Development

No branches or pull requests

2 participants