Skip to content

Commit 6e6ac74

Browse files
committed
Still need to close response body if method is returning Response
1 parent 454d608 commit 6e6ac74

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

api/src/main/java/feign/InvocationContext.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public Response response() {
6969

7070
public Object proceed() throws Exception {
7171
if (returnType == Response.class) {
72-
return response;
72+
return disconnectResponseBodyIfNeeded(response);
7373
}
7474

7575
boolean noClose = false;
@@ -107,23 +107,23 @@ public Object proceed() throws Exception {
107107
}
108108
}
109109

110-
//
111-
// private static Response disconnectResponseBodyIfNeeded(Response response) throws IOException {
112-
// final boolean shouldDisconnectResponseBody =
113-
// response.body() != null
114-
// && response.body().length() != null
115-
// && response.body().length() <= MAX_RESPONSE_BUFFER_SIZE;
116-
// if (!shouldDisconnectResponseBody) {
117-
// return response;
118-
// }
119-
//
120-
// try {
121-
// final byte[] bodyData = Util.toByteArray(response.body().asInputStream());
122-
// return response.toBuilder().body(bodyData).build();
123-
// } finally {
124-
// ensureClosed(response.body());
125-
// }
126-
// }
110+
111+
private static Response disconnectResponseBodyIfNeeded(Response response) throws IOException {
112+
final boolean shouldDisconnectResponseBody =
113+
response.body() != null
114+
&& response.body().length() != null
115+
&& response.body().length() <= MAX_RESPONSE_BUFFER_SIZE;
116+
if (!shouldDisconnectResponseBody) {
117+
return response;
118+
}
119+
120+
try {
121+
final byte[] bodyData = Util.toByteArray(response.body().asInputStream());
122+
return response.toBuilder().body(bodyData).build();
123+
} finally {
124+
ensureClosed(response.body());
125+
}
126+
}
127127

128128
private Object decode(Response response, Type returnType) {
129129
try {

0 commit comments

Comments
 (0)