mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-22 14:09:25 +00:00
Support HttpComponents 5.6
This commit updates the HttpComponents HttpClient to refer to the parsed `HttpEntity` for the content-related HTTP response headers such as encoding and body length. Closes gh-36100
This commit is contained in:
+19
@@ -18,6 +18,7 @@ package org.springframework.http.client;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -32,9 +33,11 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -60,6 +63,22 @@ class HttpComponentsClientHttpRequestFactoryTests extends AbstractHttpRequestFac
|
||||
assertHttpMethod("patch", HttpMethod.PATCH);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldDecompressWithExpectedHeaders() throws Exception {
|
||||
ClientHttpRequest request = factory.createRequest(URI.create(baseUrl + "/compress/gzip"), HttpMethod.POST);
|
||||
String message = "Hello World";
|
||||
final byte[] body = message.getBytes(StandardCharsets.UTF_8);
|
||||
StreamUtils.copy(body, request.getBody());
|
||||
|
||||
try (ClientHttpResponse response = request.execute()) {
|
||||
assertThat(response.getStatusCode()).as("Invalid status code").isEqualTo(HttpStatus.OK);
|
||||
String result = FileCopyUtils.copyToString(new InputStreamReader(response.getBody()));
|
||||
assertThat(result).as("Invalid body").isEqualTo(message);
|
||||
assertThat(response.getHeaders().get(HttpHeaders.CONTENT_ENCODING)).isNull();
|
||||
assertThat(response.getHeaders().getContentLength()).isEqualTo(-1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void assertCustomConfig() throws Exception {
|
||||
HttpClient httpClient = HttpClientBuilder.create().build();
|
||||
|
||||
Reference in New Issue
Block a user