Skip to content

Commit

Permalink
add content length check in case of json response
Browse files Browse the repository at this point in the history
  • Loading branch information
mwwoda committed Jan 31, 2024
1 parent 4e75515 commit 443c6c0
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/main/java/com/box/sdk/BoxAPIResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,16 @@ static BoxAPIResponse toBoxResponse(Response response) {
ResponseBody responseBody = response.body();
if (responseBody.contentType() == null) {
try {
return new BoxAPIResponse(response.code(),
response.request().method(),
response.request().url().toString(),
response.headers().toMultimap()
);
return emptyContentResponse(response);
} finally {
responseBody.close();
}
}
if (responseBody != null && responseBody.contentType() != null) {
if (responseBody.contentType().toString().contains(APPLICATION_JSON)) {
if (responseBody.contentLength() == 0) {
return emptyContentResponse(response);
}
String bodyAsString = "";
try {
bodyAsString = responseBody.string();
Expand Down Expand Up @@ -189,6 +188,14 @@ static BoxAPIResponse toBoxResponse(Response response) {
);
}

private static BoxAPIResponse emptyContentResponse(Response response) {
return new BoxAPIResponse(response.code(),
response.request().method(),
response.request().url().toString(),
response.headers().toMultimap()
);
}

/**
* Gets the response code returned by the API.
*
Expand Down

0 comments on commit 443c6c0

Please sign in to comment.