Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ class ExceptionGenerator {
.status(500)
.body((Response.Body) null)
.headers(testHeaders)
.request(
Request.create(
Request.HttpMethod.GET, "http://test", testHeaders, Request.Body.empty(), null))
.request(Request.create(Request.HttpMethod.GET, "http://test", testHeaders, null, null))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ Response testResponse(int status, String body, Map<String, Collection<String>> h
.status(status)
.body(body, StandardCharsets.UTF_8)
.headers(headers)
.request(
Request.create(
Request.HttpMethod.GET, "http://test", headers, Request.Body.empty(), null))
.request(Request.create(Request.HttpMethod.GET, "http://test", headers, null, null))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import static org.assertj.core.api.Assertions.assertThat;

import feign.Request;
import feign.codec.DefaultDecoder;
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors;
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DeclaredDefaultConstructorException;
Expand Down Expand Up @@ -56,11 +55,7 @@ public class AnnotationErrorDecoderExceptionConstructorsTest
private static final String NON_NULL_BODY = "A GIVEN BODY";
private static final feign.Request REQUEST =
feign.Request.create(
feign.Request.HttpMethod.GET,
"http://test",
Collections.emptyMap(),
Request.Body.empty(),
null);
feign.Request.HttpMethod.GET, "http://test", Collections.emptyMap(), null, null);
private static final feign.Request NO_REQUEST = null;
private static final Map<String, Collection<String>> NON_NULL_HEADERS = new HashMap<>();
private static final Map<String, Collection<String>> NO_HEADERS = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void buildResponse() {
Response.builder()
.status(200)
.reason("OK")
.request(Request.create(HttpMethod.GET, "/", Collections.emptyMap(), null, Util.UTF_8))
.request(Request.create(HttpMethod.GET, "/", Collections.emptyMap(), null, null))
.headers(Collections.emptyMap())
.body(carsJson(Integer.parseInt(size)), Util.UTF_8)
.build();
Expand Down
9 changes: 5 additions & 4 deletions core/src/main/java/feign/DefaultClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.GZIPInputStream;
Expand Down Expand Up @@ -187,9 +188,9 @@ else if (field.equals(ACCEPT_ENCODING)) {
connection.addRequestProperty("Accept", "*/*");
}

byte[] body = request.body();
Optional<Request.Body> body = request.body();

if (body != null) {
if (body.isPresent()) {
/*
* Ignore disableRequestBuffering flag if the empty body was set, to ensure that internal
* retry logic applies to such requests.
Expand All @@ -209,7 +210,7 @@ else if (field.equals(ACCEPT_ENCODING)) {
out = new DeflaterOutputStream(out);
}
try {
out.write(body);
body.get().writeTo(out);
} finally {
try {
out.close();
Expand All @@ -218,7 +219,7 @@ else if (field.equals(ACCEPT_ENCODING)) {
}
}

if (body == null && request.httpMethod().isWithBody()) {
if (!body.isPresent() && request.httpMethod().isWithBody()) {
// To use this Header, set 'sun.net.http.allowRestrictedHeaders' property true.
connection.addRequestProperty("Content-Length", "0");
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/feign/DefaultContract.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public DefaultContract() {
"Body annotation was empty on method %s.",
data.configKey());
if (body.indexOf('{') == -1) {
data.template().body(body);
data.template().body(Request.Body.of(body));
} else {
data.template().bodyTemplate(body);
}
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/java/feign/FeignException.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
package feign;

import static feign.Util.*;
import static feign.Util.UTF_8;
import static feign.Util.caseInsensitiveCopyOf;
import static feign.Util.checkNotNull;
import static java.lang.String.format;
import static java.util.regex.Pattern.CASE_INSENSITIVE;

Expand Down Expand Up @@ -182,7 +184,7 @@ static FeignException errorReading(Request request, Response response, IOExcepti
format("%s reading %s %s", cause.getMessage(), request.httpMethod(), request.url()),
request,
cause,
request.body(),
null,
request.headers());
}

Expand Down
22 changes: 12 additions & 10 deletions core/src/main/java/feign/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,18 @@ protected void logRequest(String configKey, Level logLevel, Request request) {
}
}

int bodyLength = 0;
if (request.body() != null) {
bodyLength = request.length();
if (logLevel.ordinal() >= Level.FULL.ordinal()) {
String bodyText =
request.charset() != null ? new String(request.body(), request.charset()) : null;
log(configKey, ""); // CRLF
log(configKey, "%s", bodyText != null ? bodyText : "Binary data");
}
}
long bodyLength =
request
.body()
.map(
body -> {
if (logLevel.ordinal() >= Level.FULL.ordinal()) {
log(configKey, ""); // CRLF
log(configKey, body.toString());
}
return body.contentLength();
})
.orElse(0L);
log(configKey, "---> END HTTP (%s-byte body)", bodyLength);
}
}
Expand Down
Loading