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

Use charset of request to create the String content. #1571

Merged
merged 3 commits into from
Mar 2, 2022

Conversation

akuhtz
Copy link
Contributor

@akuhtz akuhtz commented Jan 29, 2022

This PR fixes #1570

Copy link
Member

@velo velo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, still need unti test for the change

@@ -135,7 +135,12 @@ ClassicHttpRequest toClassicHttpRequest(Request request, Request.Options options
entity = new ByteArrayEntity(data, null);
} else {
final ContentType contentType = getContentType(request);
entity = new StringEntity(new String(data), contentType);
if (request.charset() != null) {
String content = new String(request.body(), request.charset());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use data instead?
if not, need a comment explaining why need to use request.body()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

entity = new StringEntity(new String(data), contentType);
if (request.charset() != null) {
String content = new String(request.body(), request.charset());
entity = new StringEntity(content, contentType);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this line outside the if, and let the if block just handle the String content creation?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@velo
Copy link
Member

velo commented Jan 30, 2022

Any chance of we having a unit test around this change?

@akuhtz
Copy link
Contributor Author

akuhtz commented Jan 31, 2022

Any chance of we having a unit test around this change?

I don't know how to manipulate the request.charset() to return a changed encoding, and I don't know how to change the default for a single test. The issue happens if e.g. the client has default charset ISO_8859_1 and the server has UTF_8.
The existing test already rely on UTF_8.

@velo velo merged commit f9310ae into OpenFeign:master Mar 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ApacheHttp5Client does not use charset from request to create the String content
2 participants