Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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,6 +45,8 @@ class AsyncHttpClientCall implements Cloneable, okhttp3.Call {
* @see #executeTimeoutMillis
*/
public static final long DEFAULT_EXECUTE_TIMEOUT_MILLIS = 30_000;

private static final ResponseBody EMPTY_BODY = ResponseBody.create(null, "");
/**
* Tells whether call has been executed.
*
Expand Down Expand Up @@ -254,6 +256,8 @@ private Response toOkhttpResponse(org.asynchttpclient.Response asyncHttpClientRe
? null : MediaType.parse(asyncHttpClientResponse.getContentType());
val okHttpBody = ResponseBody.create(contentType, asyncHttpClientResponse.getResponseBodyAsBytes());
rspBuilder.body(okHttpBody);
} else {
rspBuilder.body(EMPTY_BODY);
}

return rspBuilder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue;

public class AsyncHttpClientCallTest {
Expand Down Expand Up @@ -281,6 +282,19 @@ public void contentTypeIsProperlyParsedIfPresent() throws Exception {

}

@Test
public void bodyIsNotNullInResponse() throws Exception {
AsyncHttpClient client = mock(AsyncHttpClient.class);

givenResponseIsProduced(client, responseWithNoBody());

okhttp3.Response response = whenRequestIsMade(client, REQUEST);

assertEquals(response.code(), 200);
assertEquals(response.header("Server"), "nginx");
assertNotEquals(response.body(), null);
}

private void givenResponseIsProduced(AsyncHttpClient client, Response response) {
when(client.executeRequest(any(org.asynchttpclient.Request.class), any())).thenAnswer(invocation -> {
AsyncCompletionHandler<Response> handler = invocation.getArgument(1);
Expand Down Expand Up @@ -323,6 +337,13 @@ private Response responseWithBody(String contentType, String content) {
return response;
}

private Response responseWithNoBody() {
Response response = aResponse();
when(response.hasResponseBody()).thenReturn(false);
when(response.getContentType()).thenReturn(null);
return response;
}

private void doThrow(String message) {
throw new RuntimeException(message);
}
Expand Down