Reputation: 1
I use WebTestClient writing test cases in spring boot application. I need to get response body by compressing it. When I use RestTemplate I can get compressed response body.
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("Accept-Encoding", "gzip");
httpHeaders.add("Authorization", "Bearer " + token);`
HttpEntity<RequestDTO> requestEntity = new HttpEntity<>(requestDTO, httpHeaders);
esponseEntity<byte[]> responseEntity = restTemplate.exchange(baseURL + "/test",HttpMethod.POST, requestEntity, byte[].class);
When I use WebTestClient, response body not compressed. Is there any way to compressed response body when use WebTestClient.
byte[] response = webTestClient.post().uri("/test")
.header("Authorization", "Bearer " + token)
.header(HttpHeaders.ACCEPT_ENCODING, "gzip")
.body(BodyInserters.fromValue(requestDTO)).exchange()
.expectStatus().isOk()
.expectBody(byte[].class)
.returnResult().getResponseBody();
Upvotes: 0
Views: 43