Java 类org.apache.http.client.entity.InputStreamFactory 实例源码

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:AbstractEmbeddedServletContainerFactoryTests.java   
@Test
public void compressionWithoutContentSizeHeader() throws Exception {
    AbstractEmbeddedServletContainerFactory factory = getFactory();
    Compression compression = new Compression();
    compression.setEnabled(true);
    factory.setCompression(compression);
    this.container = factory.getEmbeddedServletContainer(
            new ServletRegistrationBean(new ExampleServlet(false, true), "/hello"));
    this.container.start();
    TestGzipInputStreamFactory inputStreamFactory = new TestGzipInputStreamFactory();
    Map<String, InputStreamFactory> contentDecoderMap = Collections
            .singletonMap("gzip", (InputStreamFactory) inputStreamFactory);
    getResponse(getLocalUrl("/hello"),
            new HttpComponentsClientHttpRequestFactory(HttpClientBuilder.create()
                    .setContentDecoderRegistry(contentDecoderMap).build()));
    assertThat(inputStreamFactory.wasCompressionUsed()).isTrue();
}
项目:spring-boot-concourse    文件:AbstractEmbeddedServletContainerFactoryTests.java   
@Test
public void compressionWithoutContentSizeHeader() throws Exception {
    AbstractEmbeddedServletContainerFactory factory = getFactory();
    Compression compression = new Compression();
    compression.setEnabled(true);
    factory.setCompression(compression);
    this.container = factory.getEmbeddedServletContainer(
            new ServletRegistrationBean(new ExampleServlet(false, true), "/hello"));
    this.container.start();
    TestGzipInputStreamFactory inputStreamFactory = new TestGzipInputStreamFactory();
    Map<String, InputStreamFactory> contentDecoderMap = Collections
            .singletonMap("gzip", (InputStreamFactory) inputStreamFactory);
    getResponse(getLocalUrl("/hello"),
            new HttpComponentsClientHttpRequestFactory(HttpClientBuilder.create()
                    .setContentDecoderRegistry(contentDecoderMap).build()));
    assertThat(inputStreamFactory.wasCompressionUsed()).isTrue();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:AbstractEmbeddedServletContainerFactoryTests.java   
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();
}
项目:spring-boot-concourse    文件:AbstractEmbeddedServletContainerFactoryTests.java   
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();
}
项目:purecloud-iot    文件:ResponseContentEncoding.java   
/**
 * @since 4.5
 */
public ResponseContentEncoding(final Lookup<InputStreamFactory> decoderRegistry, final boolean ignoreUnknown) {
    this.decoderRegistry = decoderRegistry != null ? decoderRegistry :
        RegistryBuilder.<InputStreamFactory>create()
                .register("gzip", GZIP)
                .register("x-gzip", GZIP)
                .register("deflate", DEFLATE)
                .build();
    this.ignoreUnknown = ignoreUnknown;
}
项目:purecloud-iot    文件:ResponseContentEncoding.java   
@Override
public void process(
        final HttpResponse response,
        final HttpContext context) throws HttpException, IOException {
    final HttpEntity entity = response.getEntity();

    final HttpClientContext clientContext = HttpClientContext.adapt(context);
    final RequestConfig requestConfig = clientContext.getRequestConfig();
    // entity can be null in case of 304 Not Modified, 204 No Content or similar
    // check for zero length entity.
    if (requestConfig.isContentCompressionEnabled() && entity != null && entity.getContentLength() != 0) {
        final Header ceheader = entity.getContentEncoding();
        if (ceheader != null) {
            final HeaderElement[] codecs = ceheader.getElements();
            for (final HeaderElement codec : codecs) {
                final String codecname = codec.getName().toLowerCase(Locale.ROOT);
                final InputStreamFactory decoderFactory = decoderRegistry.lookup(codecname);
                if (decoderFactory != null) {
                    response.setEntity(new DecompressingEntity(response.getEntity(), decoderFactory));
                    response.removeHeaders("Content-Length");
                    response.removeHeaders("Content-Encoding");
                    response.removeHeaders("Content-MD5");
                } else {
                    if (!"identity".equals(codecname) && !ignoreUnknown) {
                        throw new HttpException("Unsupported Content-Encoding: " + codec.getName());
                    }
                }
            }
        }
    }
}
项目:contestparser    文件:AbstractEmbeddedServletContainerFactoryTests.java   
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, equalTo(testContent));
    return inputStreamFactory.wasCompressionUsed();
}
项目:jbrotli    文件:BrotliDecompressingEntity.java   
BrotliDecompressingEntity(HttpEntity entity) {
  super(entity, new InputStreamFactory() {
    public InputStream create(InputStream instream) throws IOException {
      return new BrotliInputStream(instream);
    }
  });
}
项目:purecloud-iot    文件:ResponseContentEncoding.java   
/**
 * @since 4.4
 */
public ResponseContentEncoding(final Lookup<InputStreamFactory> decoderRegistry) {
    this(decoderRegistry, true);
}
项目:purecloud-iot    文件:HttpClientBuilder.java   
/**
 * Assigns a map of {@link org.apache.http.client.entity.InputStreamFactory}s
 * to be used for automatic content decompression.
 */
public final HttpClientBuilder setContentDecoderRegistry(
        final Map<String, InputStreamFactory> contentDecoderMap) {
    this.contentDecoderMap = contentDecoderMap;
    return this;
}