Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

FoxHttpRequestBody does not generate UTF-8 body #5

Closed
heffebaycay opened this issue Dec 30, 2017 · 2 comments
Closed

FoxHttpRequestBody does not generate UTF-8 body #5

heffebaycay opened this issue Dec 30, 2017 · 2 comments
Assignees
Labels
Milestone

Comments

@heffebaycay
Copy link

While integrating the hipchat-api library, I noticed an encoding issue and opened viascom/hipchat-api#30. However, digging deeper shows that the problem is caused by FoxHttp... so I'm opening an issue here as well.

Here's the problem: if the request contains a non-ASCII character in its body, the character will not be properly encoded.

The culprit is the following method:
ch.viascom.groundwork.foxhttp.body.request.FoxHttpRequestBody#writeBody

DataOutputStream wr = new DataOutputStream(outputStream);
wr.writeBytes(json);

And here's the javadoc of java.io.DataOutputStream#writeBytes:

Writes out the string to the underlying output stream as a
sequence of bytes. Each character in the string is written out, in
sequence, by discarding its high eight bits. If no exception is
thrown, the counter written is incremented by the
length of s.

Since internally writeBytes(String) calls charAt, it does not support UTF-8, which is why the character is not properly encoded in the request.

@itsmefox itsmefox added the bug label Jan 3, 2018
@itsmefox itsmefox self-assigned this Jan 3, 2018
@itsmefox itsmefox added this to the v1.3.1 milestone Jan 3, 2018
@itsmefox
Copy link
Member

itsmefox commented Jan 3, 2018

Hi @heffebaycay

Thanks for your bug report. Your analysis on viascom/hipchat-api#30 is very nice and will help a lot. I will check our code and fix this bug as soon as possible.

Cheers, Patrick

itsmefox added a commit that referenced this issue Jan 3, 2018
- Add Charset support to FoxHttpRequestBody
- Add new annotation SerializeContentType which allows to set the content type in interface, method or model level
- Update unit test to check for correct encoding
@itsmefox
Copy link
Member

itsmefox commented Feb 5, 2018

This issue is fixed in Version 1.3.1

@itsmefox itsmefox closed this as completed Feb 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants