Skip to content

Commit

Permalink
close body always for json responses
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsocha2 committed Sep 26, 2023
1 parent 0c79d17 commit 0704d13
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/main/java/com/box/sdk/BoxAPIResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,15 @@ static BoxAPIResponse toBoxResponse(Response response) {
}
ResponseBody responseBody = response.body();
if (responseBody.contentLength() == 0 || responseBody.contentType() == null) {
return new BoxAPIResponse(response.code(),
response.request().method(),
response.request().url().toString(),
response.headers().toMultimap()
);
try {
return new BoxAPIResponse(response.code(),
response.request().method(),
response.request().url().toString(),
response.headers().toMultimap()
);
} finally {
responseBody.close();
}
}
if (responseBody != null && responseBody.contentType() != null) {
if (responseBody.contentType().toString().contains(APPLICATION_JSON)) {
Expand All @@ -170,6 +174,8 @@ static BoxAPIResponse toBoxResponse(Response response) {
throw new BoxAPIException(format("Error parsing JSON:\n%s", bodyAsString), e);
} catch (IOException e) {
throw new RuntimeException("Error getting response to string", e);
} finally {
responseBody.close();
}
}
}
Expand Down

0 comments on commit 0704d13

Please sign in to comment.