Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
HttpComponents Client Source Code Files
HttpComponents Client Source Code Files are provided in the source package file, httpcomponents-client-5.2-src.zip.
You can download httpcomponents-client-5.2-src.zip as described in the previous tutorial and go to the "httpclient5/src" sub-folder to view Source Code files.
You can also browse HttpComponents Client Source Code below:
✍: FYIcenter.com
⏎ org/apache/hc/client5/http/impl/classic/ContentCompressionExec.java
/* * ==================================================================== * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package org.apache.hc.client5.http.impl.classic; import java.io.IOException; import java.util.List; import java.util.Locale; import org.apache.hc.client5.http.classic.ExecChain; import org.apache.hc.client5.http.classic.ExecChainHandler; import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.entity.BrotliDecompressingEntity; import org.apache.hc.client5.http.entity.BrotliInputStreamFactory; import org.apache.hc.client5.http.entity.DecompressingEntity; import org.apache.hc.client5.http.entity.DeflateInputStreamFactory; import org.apache.hc.client5.http.entity.GZIPInputStreamFactory; import org.apache.hc.client5.http.entity.InputStreamFactory; import org.apache.hc.client5.http.protocol.HttpClientContext; import org.apache.hc.core5.annotation.Contract; import org.apache.hc.core5.annotation.Internal; import org.apache.hc.core5.annotation.ThreadingBehavior; import org.apache.hc.core5.http.ClassicHttpRequest; import org.apache.hc.core5.http.ClassicHttpResponse; import org.apache.hc.core5.http.Header; import org.apache.hc.core5.http.HeaderElement; import org.apache.hc.core5.http.HttpEntity; import org.apache.hc.core5.http.HttpException; import org.apache.hc.core5.http.HttpHeaders; import org.apache.hc.core5.http.config.Lookup; import org.apache.hc.core5.http.config.RegistryBuilder; import org.apache.hc.core5.http.message.BasicHeaderValueParser; import org.apache.hc.core5.http.message.MessageSupport; import org.apache.hc.core5.http.message.ParserCursor; import org.apache.hc.core5.util.Args; /** * Request execution handler in the classic request execution chain * that is responsible for automatic response content decompression. * <p> * Further responsibilities such as communication with the opposite * endpoint is delegated to the next executor in the request execution * chain. * </p> * * @since 5.0 */ @Contract(threading = ThreadingBehavior.STATELESS) @Internal public final class ContentCompressionExec implements ExecChainHandler { private final Header acceptEncoding; private final Lookup<InputStreamFactory> decoderRegistry; private final boolean ignoreUnknown; /** * An empty immutable {@code String} array. */ private static final String[] EMPTY_STRING_ARRAY = {}; public ContentCompressionExec( final List<String> acceptEncoding, final Lookup<InputStreamFactory> decoderRegistry, final boolean ignoreUnknown) { final boolean brotliSupported = BrotliDecompressingEntity.isAvailable(); final String[] encoding; if (brotliSupported) { encoding = new String[] {"gzip", "x-gzip", "deflate", "br"}; } else { encoding = new String[] {"gzip", "x-gzip", "deflate"}; } this.acceptEncoding = MessageSupport.format(HttpHeaders.ACCEPT_ENCODING, acceptEncoding != null ? acceptEncoding.toArray( EMPTY_STRING_ARRAY) : encoding); if (decoderRegistry != null) { this.decoderRegistry = decoderRegistry; } else { final RegistryBuilder<InputStreamFactory> builder = RegistryBuilder.<InputStreamFactory>create() .register("gzip", GZIPInputStreamFactory.getInstance()) .register("x-gzip", GZIPInputStreamFactory.getInstance()) .register("deflate", DeflateInputStreamFactory.getInstance()); if (brotliSupported) { builder.register("br", BrotliInputStreamFactory.getInstance()); } this.decoderRegistry = builder.build(); } this.ignoreUnknown = ignoreUnknown; } public ContentCompressionExec(final boolean ignoreUnknown) { this(null, null, ignoreUnknown); } /** * Handles {@code gzip} and {@code deflate} compressed entities by using the following * decoders: * <ul> * <li>gzip - see {@link java.util.zip.GZIPInputStream}</li> * <li>deflate - see {@link org.apache.hc.client5.http.entity.DeflateInputStream}</li> * <li>brotli - see {@link org.brotli.dec.BrotliInputStream}</li> * </ul> */ public ContentCompressionExec() { this(null, null, true); } @Override public ClassicHttpResponse execute( final ClassicHttpRequest request, final ExecChain.Scope scope, final ExecChain chain) throws IOException, HttpException { Args.notNull(request, "HTTP request"); Args.notNull(scope, "Scope"); final HttpClientContext clientContext = scope.clientContext; final RequestConfig requestConfig = clientContext.getRequestConfig(); /* Signal support for Accept-Encoding transfer encodings. */ if (!request.containsHeader(HttpHeaders.ACCEPT_ENCODING) && requestConfig.isContentCompressionEnabled()) { request.addHeader(acceptEncoding); } final ClassicHttpResponse response = chain.proceed(request, scope); final HttpEntity entity = response.getEntity(); // 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 String contentEncoding = entity.getContentEncoding(); if (contentEncoding != null) { final ParserCursor cursor = new ParserCursor(0, contentEncoding.length()); final HeaderElement[] codecs = BasicHeaderValueParser.INSTANCE.parseElements(contentEncoding, cursor); 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(HttpHeaders.CONTENT_LENGTH); response.removeHeaders(HttpHeaders.CONTENT_ENCODING); response.removeHeaders(HttpHeaders.CONTENT_MD5); } else { if (!"identity".equals(codecname) && !ignoreUnknown) { throw new HttpException("Unsupported Content-Encoding: " + codec.getName()); } } } } } return response; } }
⏎ org/apache/hc/client5/http/impl/classic/ContentCompressionExec.java
Or download all them as a single archive file:
File name: httpclient5-5.2-fyi.zip File size: 625318 bytes Release date: 2022-11-10 Download
⇒ Download and Install HttpComponents Core Binary Package
⇐ Download and Install HttpComponents Client Source Package
2023-03-26, 23336👍, 1💬
Popular Posts:
iText is an ideal library for developers looking to enhance web- and other applications with dynamic...
Apache Log4j 1.2 Bridge allows applications coded to use Log4j 1.2 API to use Log4j 2 instead. Bytec...
Apache BCEL Source Code Files are inside the Apache BCEL source package file like bcel-6.6.1-src.zip...
JDOM provides a solution for using XML from Java that is as simple as Java itself. There is no compe...
commons-lang-1.0.1.jar is the JAR file for Apache Commons Lang 1.0.1, which provides a host of helpe...