Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
public final class ContentCompressionAsyncExec implements AsyncExecChainHandler {

private final Lookup<UnaryOperator<AsyncDataConsumer>> decoders;
private final boolean ignoreUnknown;

public ContentCompressionAsyncExec(
final LinkedHashMap<String, UnaryOperator<AsyncDataConsumer>> decoderMap,
Expand All @@ -73,7 +72,6 @@ public ContentCompressionAsyncExec(
final RegistryBuilder<UnaryOperator<AsyncDataConsumer>> rb = RegistryBuilder.create();
decoderMap.forEach(rb::register);
this.decoders = rb.build();
this.ignoreUnknown = ignoreUnknown;
}

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


Expand Down Expand Up @@ -132,7 +129,7 @@ public AsyncDataConsumer handleResponse(final HttpResponse rsp,
final UnaryOperator<AsyncDataConsumer> op = decoders.lookup(token);
if (op != null) {
downstream = op.apply(downstream);
} else if (!ignoreUnknown) {
} else {
throw new HttpException("Unsupported Content-Encoding: " + token);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,16 @@ public final class ContentCompressionExec implements ExecChainHandler {

private final Header acceptEncoding;
private final Lookup<UnaryOperator<HttpEntity>> decoderRegistry;
private final boolean ignoreUnknown;

public ContentCompressionExec(
final List<String> acceptEncoding,
final Lookup<UnaryOperator<HttpEntity>> decoderRegistry,
final boolean ignoreUnknown) {
final Lookup<UnaryOperator<HttpEntity>> decoderRegistry) {
this.acceptEncoding = MessageSupport.headerOfTokens(HttpHeaders.ACCEPT_ENCODING,
Args.notEmpty(acceptEncoding, "Encoding list"));
this.decoderRegistry = Args.notNull(decoderRegistry, "Decoder register");
this.ignoreUnknown = ignoreUnknown;
}

public ContentCompressionExec(final boolean ignoreUnknown) {
public ContentCompressionExec() {
final Map<ContentCoding, UnaryOperator<HttpEntity>> decoderMap = new EnumMap<>(ContentCoding.class);
for (final ContentCoding c : ContentCoding.values()) {
final UnaryOperator<HttpEntity> d = ContentCodecRegistry.decoder(c);
Expand All @@ -109,13 +106,6 @@ public ContentCompressionExec(final boolean ignoreUnknown) {
}
this.acceptEncoding = MessageSupport.headerOfTokens(HttpHeaders.ACCEPT_ENCODING, acceptList);
this.decoderRegistry = builder.build();
this.ignoreUnknown = ignoreUnknown;
}

/**
*/
public ContentCompressionExec() {
this(true);
}

@Override
Expand Down Expand Up @@ -152,7 +142,7 @@ public ClassicHttpResponse execute(
response.removeHeaders(HttpHeaders.CONTENT_LENGTH);
response.removeHeaders(HttpHeaders.CONTENT_ENCODING);
response.removeHeaders(HttpHeaders.CONTENT_MD5);
} else if (!"identity".equals(codecname) && !ignoreUnknown) {
} else if (!"identity".equals(codecname)) {
throw new HttpException("Unsupported Content-Encoding: " + codec.getName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -981,13 +981,13 @@ public CloseableHttpClient build() {
final Registry<UnaryOperator<HttpEntity>> decoderRegistry = b2.build();

execChainDefinition.addFirst(
new ContentCompressionExec(encodings, decoderRegistry, true),
new ContentCompressionExec(encodings, decoderRegistry),
ChainElement.COMPRESS.name());

} else {
// Use the default decoders from ContentCodecRegistry
execChainDefinition.addFirst(
new ContentCompressionExec(true),
new ContentCompressionExec(),
ChainElement.COMPRESS.name());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void testUnknownContentEncoding() throws Exception {
final HttpEntity original = EntityBuilder.create().setText("encoded stuff").setContentEncoding("whatever").build();
response.setEntity(original);

impl = new ContentCompressionExec(false);
impl = new ContentCompressionExec();

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

Expand Down
Loading