Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions core/src/test/java/feign/client/AbstractClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,18 @@ public void contentTypeDefaultsToRequestCharset() throws Exception {
assertThat(body).isEqualToIgnoringCase("àáâãäåèéêë");
}

@Test
public void bodyKeepsRequestCharsetWithoutContentType() throws Exception {
server.enqueue(new MockResponse().setBody("foo"));
TestInterface api =
newBuilder().target(TestInterface.class, "http://localhost:" + server.getPort());

api.postWithoutContentType("日本語 àáâ");

String body = server.takeRequest().getBody().readUtf8();
assertThat(body).isEqualTo("日本語 àáâ");
}

@Test
public void defaultCollectionFormat() throws Exception {
server.enqueue(new MockResponse().setBody("body"));
Expand Down Expand Up @@ -625,6 +637,9 @@ public interface TestInterface {
@RequestLine("POST /")
String postEmptyStringBody(String body);

@RequestLine("POST /")
String postWithoutContentType(String body);

@RequestLine("PUT")
String noPutBody();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,12 @@ HttpUriRequest toHttpUriRequest(Request request, Request.Options options)
// request body
if (request.body() != null) {
HttpEntity entity = null;
if (request.charset() != null) {
ContentType contentType = getContentType(request);
ContentType contentType = request.charset() != null ? getContentType(request) : null;
if (contentType != null) {
String content = new String(request.body(), request.charset());
entity = new StringEntity(content, contentType);
} else {
// without a content type a StringEntity would encode the body as ISO-8859-1
entity = new ByteArrayEntity(request.body());
}

Expand Down