Skip to content

Commit 9d38e5f

Browse files
committed
Undeprecate InputStreamFactory and restore contentDecoderMap functionality in HttpClientBuilder
1 parent e907ae0 commit 9d38e5f

File tree

2 files changed

+10
-33
lines changed

2 files changed

+10
-33
lines changed

httpclient5/src/main/java/org/apache/hc/client5/http/entity/InputStreamFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@
3131

3232
/**
3333
* Factory for decorated {@link InputStream}s.
34-
* @deprecated Replaced by {@link org.apache.hc.client5.http.entity.compress.Decoder}.
3534
* @since 4.4
3635
*/
37-
@Deprecated
36+
@FunctionalInterface
3837
public interface InputStreamFactory {
3938

4039
InputStream create(InputStream inputStream) throws IOException;

httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@
5656
import org.apache.hc.client5.http.cookie.CookieSpecFactory;
5757
import org.apache.hc.client5.http.cookie.CookieStore;
5858
import org.apache.hc.client5.http.entity.InputStreamFactory;
59-
import org.apache.hc.client5.http.entity.compress.ContentCodecRegistry;
60-
import org.apache.hc.client5.http.entity.compress.ContentCoding;
59+
import org.apache.hc.client5.http.entity.compress.DecompressingEntity;
6160
import org.apache.hc.client5.http.impl.ChainElement;
6261
import org.apache.hc.client5.http.impl.CookieSpecSupport;
6362
import org.apache.hc.client5.http.impl.DefaultAuthenticationStrategy;
@@ -215,7 +214,6 @@ private ExecInterceptorEntry(
215214
private BackoffManager backoffManager;
216215
private Lookup<AuthSchemeFactory> authSchemeRegistry;
217216
private Lookup<CookieSpecFactory> cookieSpecRegistry;
218-
@Deprecated
219217
private LinkedHashMap<String, InputStreamFactory> contentDecoderMap;
220218
private CookieStore cookieStore;
221219
private CredentialsProvider credentialsProvider;
@@ -239,12 +237,6 @@ private ExecInterceptorEntry(
239237

240238
private List<Closeable> closeables;
241239

242-
/**
243-
* Custom decoders keyed by {@link ContentCoding}.
244-
*
245-
*/
246-
private LinkedHashMap<ContentCoding, UnaryOperator<HttpEntity>> contentDecoder;
247-
248240
public static HttpClientBuilder create() {
249241
return new HttpClientBuilder();
250242
}
@@ -714,23 +706,6 @@ public final HttpClientBuilder setContentDecoderRegistry(
714706
return this;
715707
}
716708

717-
/**
718-
* Sets a map of {@linkplain java.util.function.UnaryOperator}&lt;HttpEntity&gt; decoders,
719-
* keyed by {@link ContentCoding}, to be used for automatic response decompression.
720-
*
721-
* @param contentDecoder decoder map, or {@code null} to fall back to the
722-
* defaults from {@link ContentCodecRegistry}.
723-
* @return this builder.
724-
*
725-
* @since 5.6
726-
*/
727-
public final HttpClientBuilder setContentDecoder(
728-
final LinkedHashMap<ContentCoding, UnaryOperator<HttpEntity>> contentDecoder) {
729-
this.contentDecoder = contentDecoder;
730-
return this;
731-
}
732-
733-
734709
/**
735710
* Sets default {@link RequestConfig} instance which will be used
736711
* for request execution if not explicitly set in the client execution
@@ -992,13 +967,16 @@ public CloseableHttpClient build() {
992967

993968
if (!contentCompressionDisabled) {
994969
// Custom decoder map supplied by the caller
995-
if (contentDecoder != null) {
996-
final List<String> encodings = new ArrayList<>(contentDecoder.size());
970+
if (contentDecoderMap != null) {
971+
final List<String> encodings = new ArrayList<>(contentDecoderMap.size());
997972
final RegistryBuilder<UnaryOperator<HttpEntity>> b2 = RegistryBuilder.create();
998-
for (final Map.Entry<ContentCoding, UnaryOperator<HttpEntity>> entry : contentDecoder.entrySet()) {
999-
final String token = entry.getKey().token();
973+
for (final Map.Entry<String, InputStreamFactory> entry : contentDecoderMap.entrySet()) {
974+
final String token = entry.getKey();
975+
final InputStreamFactory inputStreamFactory = entry.getValue();
1000976
encodings.add(token);
1001-
b2.register(token, entry.getValue());
977+
b2.register(token, httpEntity -> new DecompressingEntity(
978+
httpEntity,
979+
inputStreamFactory::create));
1002980
}
1003981
final Registry<UnaryOperator<HttpEntity>> decoderRegistry = b2.build();
1004982

0 commit comments

Comments
 (0)