Skip to content

Commit 216dbf7

Browse files
authored
revert: move Request.Body streaming breaking changes off master, they belong to 14.x (#3409)
Signed-off-by: Marvin Froeder <velo.br@gmail.com>
1 parent 18fe771 commit 216dbf7

120 files changed

Lines changed: 1037 additions & 2088 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

MIGRATION-v14.md

Lines changed: 0 additions & 421 deletions
This file was deleted.

annotation-error-decoder/src/main/java/feign/error/ExceptionGenerator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ class ExceptionGenerator {
4545
.status(500)
4646
.body((Response.Body) null)
4747
.headers(testHeaders)
48-
.request(Request.create(Request.HttpMethod.GET, "http://test", testHeaders, null, null))
48+
.request(
49+
Request.create(
50+
Request.HttpMethod.GET, "http://test", testHeaders, Request.Body.empty(), null))
4951
.build();
5052
}
5153

annotation-error-decoder/src/test/java/feign/error/AbstractAnnotationErrorDecoderTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ Response testResponse(int status, String body, Map<String, Collection<String>> h
4545
.status(status)
4646
.body(body, StandardCharsets.UTF_8)
4747
.headers(headers)
48-
.request(Request.create(Request.HttpMethod.GET, "http://test", headers, null, null))
48+
.request(
49+
Request.create(
50+
Request.HttpMethod.GET, "http://test", headers, Request.Body.empty(), null))
4951
.build();
5052
}
5153
}

annotation-error-decoder/src/test/java/feign/error/AnnotationErrorDecoderExceptionConstructorsTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

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

20+
import feign.Request;
2021
import feign.codec.DefaultDecoder;
2122
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors;
2223
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DeclaredDefaultConstructorException;
@@ -55,7 +56,11 @@ public class AnnotationErrorDecoderExceptionConstructorsTest
5556
private static final String NON_NULL_BODY = "A GIVEN BODY";
5657
private static final feign.Request REQUEST =
5758
feign.Request.create(
58-
feign.Request.HttpMethod.GET, "http://test", Collections.emptyMap(), null, null);
59+
feign.Request.HttpMethod.GET,
60+
"http://test",
61+
Collections.emptyMap(),
62+
Request.Body.empty(),
63+
null);
5964
private static final feign.Request NO_REQUEST = null;
6065
private static final Map<String, Collection<String>> NON_NULL_HEADERS = new HashMap<>();
6166
private static final Map<String, Collection<String>> NO_HEADERS = null;

benchmark/src/main/java/feign/benchmark/DecoderIteratorsBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void buildResponse() {
8282
Response.builder()
8383
.status(200)
8484
.reason("OK")
85-
.request(Request.create(HttpMethod.GET, "/", Collections.emptyMap(), null, null))
85+
.request(Request.create(HttpMethod.GET, "/", Collections.emptyMap(), null, Util.UTF_8))
8686
.headers(Collections.emptyMap())
8787
.body(carsJson(Integer.parseInt(size)), Util.UTF_8)
8888
.build();

core/src/main/java/feign/DefaultClient.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.util.Collection;
3333
import java.util.List;
3434
import java.util.Map;
35-
import java.util.Optional;
3635
import java.util.TreeMap;
3736
import java.util.zip.DeflaterOutputStream;
3837
import java.util.zip.GZIPInputStream;
@@ -188,9 +187,9 @@ else if (field.equals(ACCEPT_ENCODING)) {
188187
connection.addRequestProperty("Accept", "*/*");
189188
}
190189

191-
Optional<Request.Body> body = request.body();
190+
byte[] body = request.body();
192191

193-
if (body.isPresent()) {
192+
if (body != null) {
194193
/*
195194
* Ignore disableRequestBuffering flag if the empty body was set, to ensure that internal
196195
* retry logic applies to such requests.
@@ -210,7 +209,7 @@ else if (field.equals(ACCEPT_ENCODING)) {
210209
out = new DeflaterOutputStream(out);
211210
}
212211
try {
213-
body.get().writeTo(out);
212+
out.write(body);
214213
} finally {
215214
try {
216215
out.close();
@@ -219,7 +218,7 @@ else if (field.equals(ACCEPT_ENCODING)) {
219218
}
220219
}
221220

222-
if (!body.isPresent() && request.httpMethod().isWithBody()) {
221+
if (body == null && request.httpMethod().isWithBody()) {
223222
// To use this Header, set 'sun.net.http.allowRestrictedHeaders' property true.
224223
connection.addRequestProperty("Content-Length", "0");
225224
}

core/src/main/java/feign/DefaultContract.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public DefaultContract() {
7676
"Body annotation was empty on method %s.",
7777
data.configKey());
7878
if (body.indexOf('{') == -1) {
79-
data.template().body(Request.Body.of(body));
79+
data.template().body(body);
8080
} else {
8181
data.template().bodyTemplate(body);
8282
}

core/src/main/java/feign/FeignException.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
*/
1616
package feign;
1717

18-
import static feign.Util.UTF_8;
19-
import static feign.Util.caseInsensitiveCopyOf;
20-
import static feign.Util.checkNotNull;
18+
import static feign.Util.*;
2119
import static java.lang.String.format;
2220
import static java.util.regex.Pattern.CASE_INSENSITIVE;
2321

@@ -184,7 +182,7 @@ static FeignException errorReading(Request request, Response response, IOExcepti
184182
format("%s reading %s %s", cause.getMessage(), request.httpMethod(), request.url()),
185183
request,
186184
cause,
187-
null,
185+
request.body(),
188186
request.headers());
189187
}
190188

core/src/main/java/feign/Logger.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,16 @@ protected void logRequest(String configKey, Level logLevel, Request request) {
7878
}
7979
}
8080

81-
long bodyLength =
82-
request
83-
.body()
84-
.map(
85-
body -> {
86-
if (logLevel.ordinal() >= Level.FULL.ordinal()) {
87-
log(configKey, ""); // CRLF
88-
log(configKey, "%s", body.toString());
89-
}
90-
return body.contentLength();
91-
})
92-
.orElse(0L);
81+
int bodyLength = 0;
82+
if (request.body() != null) {
83+
bodyLength = request.length();
84+
if (logLevel.ordinal() >= Level.FULL.ordinal()) {
85+
String bodyText =
86+
request.charset() != null ? new String(request.body(), request.charset()) : null;
87+
log(configKey, ""); // CRLF
88+
log(configKey, "%s", bodyText != null ? bodyText : "Binary data");
89+
}
90+
}
9391
log(configKey, "---> END HTTP (%s-byte body)", bodyLength);
9492
}
9593
}

0 commit comments

Comments
 (0)