Search in sources :

Example 1 with InputStreamFactory

use of org.apache.http.client.entity.InputStreamFactory in project spring-boot by spring-projects.

the class AbstractServletWebServerFactoryTests method doTestCompression.

private boolean doTestCompression(int contentSize, String[] mimeTypes, String[] excludedUserAgents) throws Exception {
    String testContent = setUpFactoryForCompression(contentSize, mimeTypes, excludedUserAgents);
    TestGzipInputStreamFactory inputStreamFactory = new TestGzipInputStreamFactory();
    Map<String, InputStreamFactory> contentDecoderMap = Collections.singletonMap("gzip", (InputStreamFactory) inputStreamFactory);
    String response = getResponse(getLocalUrl("/test.txt"), new HttpComponentsClientHttpRequestFactory(HttpClientBuilder.create().setUserAgent("testUserAgent").setContentDecoderRegistry(contentDecoderMap).build()));
    assertThat(response).isEqualTo(testContent);
    return inputStreamFactory.wasCompressionUsed();
}
Also used : HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) InputStreamFactory(org.apache.http.client.entity.InputStreamFactory)

Example 2 with InputStreamFactory

use of org.apache.http.client.entity.InputStreamFactory in project spring-boot by spring-projects.

the class AbstractServletWebServerFactoryTests method doTestCompression.

private boolean doTestCompression(int contentSize, String[] mimeTypes, String[] excludedUserAgents, HttpMethod method) throws Exception {
    String testContent = setUpFactoryForCompression(contentSize, mimeTypes, excludedUserAgents);
    TestGzipInputStreamFactory inputStreamFactory = new TestGzipInputStreamFactory();
    Map<String, InputStreamFactory> contentDecoderMap = Collections.singletonMap("gzip", inputStreamFactory);
    String response = getResponse(getLocalUrl("/test.txt"), method, new HttpComponentsClientHttpRequestFactory(HttpClientBuilder.create().setUserAgent("testUserAgent").setContentDecoderRegistry(contentDecoderMap).build()));
    assertThat(response).isEqualTo(testContent);
    return inputStreamFactory.wasCompressionUsed();
}
Also used : HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) InputStreamFactory(org.apache.http.client.entity.InputStreamFactory)

Example 3 with InputStreamFactory

use of org.apache.http.client.entity.InputStreamFactory in project spring-boot by spring-projects.

the class AbstractServletWebServerFactoryTests method compressionWithoutContentSizeHeader.

@Test
void compressionWithoutContentSizeHeader() throws Exception {
    AbstractServletWebServerFactory factory = getFactory();
    Compression compression = new Compression();
    compression.setEnabled(true);
    factory.setCompression(compression);
    this.webServer = factory.getWebServer(new ServletRegistrationBean<>(new ExampleServlet(false, true), "/hello"));
    this.webServer.start();
    TestGzipInputStreamFactory inputStreamFactory = new TestGzipInputStreamFactory();
    Map<String, InputStreamFactory> contentDecoderMap = Collections.singletonMap("gzip", inputStreamFactory);
    getResponse(getLocalUrl("/hello"), new HttpComponentsClientHttpRequestFactory(this.httpClientBuilder.get().setContentDecoderRegistry(contentDecoderMap).build()));
    assertThat(inputStreamFactory.wasCompressionUsed()).isTrue();
}
Also used : Compression(org.springframework.boot.web.server.Compression) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) InputStreamFactory(org.apache.http.client.entity.InputStreamFactory) ExampleServlet(org.springframework.boot.testsupport.web.servlet.ExampleServlet) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

InputStreamFactory (org.apache.http.client.entity.InputStreamFactory)3 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)3 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 ExampleServlet (org.springframework.boot.testsupport.web.servlet.ExampleServlet)1 Compression (org.springframework.boot.web.server.Compression)1 ServletRegistrationBean (org.springframework.boot.web.servlet.ServletRegistrationBean)1