Skip to content

Commit 97e4041

Browse files
committed
Unsupported content encoding to be treated as an error
1 parent 99d4a5e commit 97e4041

File tree

4 files changed

+7
-20
lines changed

4 files changed

+7
-20
lines changed

httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/ContentCompressionAsyncExec.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
public final class ContentCompressionAsyncExec implements AsyncExecChainHandler {
6363

6464
private final Lookup<UnaryOperator<AsyncDataConsumer>> decoders;
65-
private final boolean ignoreUnknown;
6665

6766
public ContentCompressionAsyncExec(
6867
final LinkedHashMap<String, UnaryOperator<AsyncDataConsumer>> decoderMap,
@@ -73,7 +72,6 @@ public ContentCompressionAsyncExec(
7372
final RegistryBuilder<UnaryOperator<AsyncDataConsumer>> rb = RegistryBuilder.create();
7473
decoderMap.forEach(rb::register);
7574
this.decoders = rb.build();
76-
this.ignoreUnknown = ignoreUnknown;
7775
}
7876

7977
/**
@@ -86,7 +84,6 @@ public ContentCompressionAsyncExec() {
8684
this.decoders = RegistryBuilder.<UnaryOperator<AsyncDataConsumer>>create()
8785
.register(ContentCoding.DEFLATE.token(), map.get(ContentCoding.DEFLATE.token()))
8886
.build();
89-
this.ignoreUnknown = true;
9087
}
9188

9289

@@ -132,7 +129,7 @@ public AsyncDataConsumer handleResponse(final HttpResponse rsp,
132129
final UnaryOperator<AsyncDataConsumer> op = decoders.lookup(token);
133130
if (op != null) {
134131
downstream = op.apply(downstream);
135-
} else if (!ignoreUnknown) {
132+
} else {
136133
throw new HttpException("Unsupported Content-Encoding: " + token);
137134
}
138135
}

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,16 @@ public final class ContentCompressionExec implements ExecChainHandler {
7575

7676
private final Header acceptEncoding;
7777
private final Lookup<UnaryOperator<HttpEntity>> decoderRegistry;
78-
private final boolean ignoreUnknown;
7978

8079
public ContentCompressionExec(
8180
final List<String> acceptEncoding,
82-
final Lookup<UnaryOperator<HttpEntity>> decoderRegistry,
83-
final boolean ignoreUnknown) {
81+
final Lookup<UnaryOperator<HttpEntity>> decoderRegistry) {
8482
this.acceptEncoding = MessageSupport.headerOfTokens(HttpHeaders.ACCEPT_ENCODING,
8583
Args.notEmpty(acceptEncoding, "Encoding list"));
8684
this.decoderRegistry = Args.notNull(decoderRegistry, "Decoder register");
87-
this.ignoreUnknown = ignoreUnknown;
8885
}
8986

90-
public ContentCompressionExec(final boolean ignoreUnknown) {
87+
public ContentCompressionExec() {
9188
final Map<ContentCoding, UnaryOperator<HttpEntity>> decoderMap = new EnumMap<>(ContentCoding.class);
9289
for (final ContentCoding c : ContentCoding.values()) {
9390
final UnaryOperator<HttpEntity> d = ContentCodecRegistry.decoder(c);
@@ -109,13 +106,6 @@ public ContentCompressionExec(final boolean ignoreUnknown) {
109106
}
110107
this.acceptEncoding = MessageSupport.headerOfTokens(HttpHeaders.ACCEPT_ENCODING, acceptList);
111108
this.decoderRegistry = builder.build();
112-
this.ignoreUnknown = ignoreUnknown;
113-
}
114-
115-
/**
116-
*/
117-
public ContentCompressionExec() {
118-
this(true);
119109
}
120110

121111
@Override
@@ -152,7 +142,7 @@ public ClassicHttpResponse execute(
152142
response.removeHeaders(HttpHeaders.CONTENT_LENGTH);
153143
response.removeHeaders(HttpHeaders.CONTENT_ENCODING);
154144
response.removeHeaders(HttpHeaders.CONTENT_MD5);
155-
} else if (!"identity".equals(codecname) && !ignoreUnknown) {
145+
} else if (!"identity".equals(codecname)) {
156146
throw new HttpException("Unsupported Content-Encoding: " + codec.getName());
157147
}
158148
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,13 +981,13 @@ public CloseableHttpClient build() {
981981
final Registry<UnaryOperator<HttpEntity>> decoderRegistry = b2.build();
982982

983983
execChainDefinition.addFirst(
984-
new ContentCompressionExec(encodings, decoderRegistry, true),
984+
new ContentCompressionExec(encodings, decoderRegistry),
985985
ChainElement.COMPRESS.name());
986986

987987
} else {
988988
// Use the default decoders from ContentCodecRegistry
989989
execChainDefinition.addFirst(
990-
new ContentCompressionExec(true),
990+
new ContentCompressionExec(),
991991
ChainElement.COMPRESS.name());
992992
}
993993
}

httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestContentCompressionExec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ void testUnknownContentEncoding() throws Exception {
206206
final HttpEntity original = EntityBuilder.create().setText("encoded stuff").setContentEncoding("whatever").build();
207207
response.setEntity(original);
208208

209-
impl = new ContentCompressionExec(false);
209+
impl = new ContentCompressionExec();
210210

211211
Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
212212

0 commit comments

Comments
 (0)