@ -18,6 +18,7 @@ package org.springframework.http.client;
@@ -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;
@@ -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
@@ -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 ( ) ;