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
File corrupted on post when using feign-form with feign httpclient #18
Comments
Apparently, default charset is ISO-8859-1 (https://tools.ietf.org/html/rfc2616#section-3.4.1). Why feign-form uses UTF_8 ? |
ISO-8859-1 - is a default only for English, UTF-8 is more common. I'm not going to implement support for another charsets, because in my opinion it is unnecessarily to use something different from UTF-8/UTF-16 in 21 century... But if you want, you could create a pull request with different charsets support and tests, I merge it ASAP |
Thank you @xxlabaza for your response. My problem comes from the use of feign-httpclient (which uses ISO-8859-1 as default charset if it's not specified in content-type (e.g Content-type: multipart/form-data; boundary=xxxxxxxx)) and feign-form which set UTF-8 as request default charset. I'll find another way to fix it. |
Hi, I have a similar problem. I try to send binary file (a PNG image) as a So, is it really mandatory to set charset for such cases? |
@leveluptor could you tell which Feign-Form version do you use? |
I'm using feign-form 3.0.0, feign-core and feign-httpclient 3.5.1. Here is a sample gradle project: https://github.com/leveluptor/feignforms-demo. How to reproduce the problem:
For Feign client with a workaround it will look like this:
The first one is a weird mix of slightly invalid unicode symbols, but the second one is a good base64-encoded image. If I paste There is another way to check, it's more reliable, but requires boring walking through the debugger.
@Override
public Response execute(Request request, Request.Options options) throws IOException {
HttpUriRequest httpUriRequest;
try {
httpUriRequest = toHttpUriRequest(request, options);
} catch (URISyntaxException e) {
throw new IOException("URL '" + request.url() + "' couldn't be parsed into a URI", e);
}
HttpResponse httpResponse = client.execute(httpUriRequest); // <-- BREAKPOINT
return toFeignResponse(httpResponse).toBuilder().request(request).build();
}
Overall, this looks like an interesting problem involving both |
Fixed in version 3.0.3 |
@xxlabaza Thanks! |
Hi,
I need help about an issue I'm facing when I use feign-form with feign httpclient.
Basically, the MultipartEncodedDataProcessor set body with a UTF_8 charset.
whereas feign/httpclient/ApacheHttpClient.java process it as the StringEntity and not a ByteArrayEntity. (I added some comment to explain the issue).
//request body
if (request.body() != null) {
HttpEntity entity = null;
// charset is UTF-8
if (request.charset() != null) {
// extract content-type with no charset because of Content-type header looks like Content-Type: multipart/form-data; boundary=AaB03x)
ContentType contentType = getContentType(request);
// convert body to string with UTF_8 charset
String content = new String(request.body(), request.charset());
// create a StringEntity with defaut charset ISO-8859-1 (referred to RFC) when no charset in content-type. So the entity can be corrupted.
entity = new StringEntity(content, contentType);
} else {
entity = new ByteArrayEntity(request.body());
}
Is it mandatory to set the charset in template.body(outputStream.toByteArray(), UTF_8);?
Could we just set body like this template.body(outputStream.toByteArray());
Regards,
The text was updated successfully, but these errors were encountered: