Skip to content

Commit 9099978

Browse files
Replace the old InputStreamFactory registries with the new Decoder / Encoder pipeline (#660)
* Replace the old InputStreamFactory registries with the new Decoder / Encoder pipeline. Adds ContentCodecRegistry, rewrites DecompressingEntity, updates HttpClient internals and tests, deprecates legacy helpers, and keeps backward compatibility. * Unify content-coding support: replace InputStreamFactory with symmetric Encoder/Decoder API, introduce IOFunction and ContentCodecRegistry, update DecompressingEntity and all tests accordingly. * Use UnaryOperator instead
1 parent e02c106 commit 9099978

23 files changed

Lines changed: 528 additions & 295 deletions

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@
3131
/**
3232
* {@link org.apache.hc.core5.http.io.entity.HttpEntityWrapper} responsible for
3333
* handling br Content Coded responses.
34+
* @deprecated See {@link org.apache.hc.client5.http.entity.compress.ContentCodecRegistry#decoder(org.apache.hc.client5.http.entity.compress.ContentCoding)}
3435
*
3536
* @see GzipDecompressingEntity
3637
* @since 5.2
3738
*/
39+
@Deprecated
3840
public class BrotliDecompressingEntity extends DecompressingEntity {
3941
/**
4042
* Creates a new {@link DecompressingEntity}.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@
3535

3636
/**
3737
* {@link InputStreamFactory} for handling Brotli Content Coded responses.
38-
*
38+
* @deprecated See {@link org.apache.hc.client5.http.entity.compress.ContentCodecRegistry#decoder(org.apache.hc.client5.http.entity.compress.ContentCoding)}
3939
* @since 5.2
4040
*/
4141
@Contract(threading = ThreadingBehavior.STATELESS)
42+
@Deprecated
4243
public class BrotliInputStreamFactory implements InputStreamFactory {
4344

4445
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636

3737
/**
3838
* Common base class for decompressing {@link HttpEntity} implementations.
39-
*
40-
* @since 4.4
39+
* @deprecated See {@link org.apache.hc.client5.http.entity.compress.ContentCodecRegistry#decoder(org.apache.hc.client5.http.entity.compress.ContentCoding)}
4140
*/
41+
@Deprecated
4242
public class DecompressingEntity extends HttpEntityWrapper {
4343

4444
/**

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@
3939
* rather than {@code deflate} streams. We handle both types in here,
4040
* since that's what is seen on the internet. Moral - prefer
4141
* {@code gzip}!
42+
* @deprecated See {@link org.apache.hc.client5.http.entity.compress.ContentCodecRegistry#decoder(org.apache.hc.client5.http.entity.compress.ContentCoding)}
4243
*
4344
* @see GzipDecompressingEntity
4445
*
4546
* @since 4.1
4647
*/
48+
@Deprecated
4749
public class DeflateDecompressingEntity extends DecompressingEntity {
4850

4951
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@
3535

3636
/**
3737
* {@link InputStreamFactory} for handling Deflate Content Coded responses.
38-
*
38+
* @deprecated Use {@link org.apache.hc.client5.http.entity.compress.ContentCodecRegistry#decoder(org.apache.hc.client5.http.entity.compress.ContentCoding)}
3939
* @since 5.0
4040
*/
41+
@Deprecated
4142
@Contract(threading = ThreadingBehavior.STATELESS)
4243
public class DeflateInputStreamFactory implements InputStreamFactory {
4344

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
import java.util.Arrays;
3434
import java.util.List;
3535

36+
import org.apache.hc.client5.http.entity.compress.ContentCodecRegistry;
3637
import org.apache.hc.client5.http.entity.compress.ContentCoding;
37-
import org.apache.hc.client5.http.entity.compress.ContentEncoderRegistry;
3838
import org.apache.hc.core5.http.ContentType;
3939
import org.apache.hc.core5.http.HttpEntity;
4040
import org.apache.hc.core5.http.NameValuePair;
@@ -439,12 +439,12 @@ public HttpEntity build() {
439439
throw new IllegalStateException("No entity set");
440440
}
441441
if (compressWith != null) {
442-
final ContentEncoderRegistry.EncoderFactory f = ContentEncoderRegistry.lookup(compressWith);
443-
if (f == null) {
442+
final HttpEntity compressed = ContentCodecRegistry.wrap(compressWith, e);
443+
if (compressed == null) {
444444
throw new UnsupportedOperationException(
445445
"No encoder available for content-coding '" + compressWith.token() + '\'');
446446
}
447-
return f.wrap(e);
447+
return compressed;
448448
}
449449
return e;
450450
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,14 @@
3636

3737
/**
3838
* {@link InputStreamFactory} for handling GZIPContent Coded responses.
39-
*
39+
* @deprecated – the public extension point has moved to
40+
* {@link org.apache.hc.client5.http.entity.compress.Decoder}.
41+
* For built-in gzip support use
42+
* {@code ContentCodecRegistry.decoder(ContentCoding.GZIP)} or
43+
* wrap a stream directly with
4044
* @since 5.0
4145
*/
46+
@Deprecated
4247
@Contract(threading = ThreadingBehavior.STATELESS)
4348
public class GZIPInputStreamFactory implements InputStreamFactory {
4449

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@
3232
* {@link org.apache.hc.core5.http.io.entity.HttpEntityWrapper} for handling
3333
* gzip Content Coded responses.
3434
*
35+
* @deprecated See {@link org.apache.hc.client5.http.entity.compress.ContentCodecRegistry#decoder(org.apache.hc.client5.http.entity.compress.ContentCoding)}
36+
*
3537
* @since 4.1
3638
*/
39+
@Deprecated
3740
public class GzipDecompressingEntity extends DecompressingEntity {
3841

3942
/**

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

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

3232
/**
3333
* Factory for decorated {@link InputStream}s.
34-
*
34+
* @deprecated Replaced by {@link org.apache.hc.client5.http.entity.compress.Decoder}.
3535
* @since 4.4
3636
*/
37+
@Deprecated
3738
public interface InputStreamFactory {
3839

3940
InputStream create(InputStream inputStream) throws IOException;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535

3636
/**
3737
* Lazy initializes from an {@link InputStream} wrapper.
38+
* @deprecated Superseded by {@link org.apache.hc.client5.http.entity.compress.DecompressingEntity}.
3839
*/
40+
@Deprecated
3941
class LazyDecompressingInputStream extends FilterInputStream {
4042

4143
private final InputStreamFactory inputStreamFactory;

0 commit comments

Comments
 (0)