HTTPCLIENT-1643: tolerate unknown content encodings by default
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1676713 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
50cb3a3d4e
commit
6f4a762197
|
@ -78,17 +78,33 @@ public class ResponseContentEncoding implements HttpResponseInterceptor {
|
||||||
};
|
};
|
||||||
|
|
||||||
private final Lookup<InputStreamFactory> decoderRegistry;
|
private final Lookup<InputStreamFactory> decoderRegistry;
|
||||||
|
private final boolean ignoreUnknown;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 4.4
|
* @since 4.5
|
||||||
*/
|
*/
|
||||||
public ResponseContentEncoding(final Lookup<InputStreamFactory> decoderRegistry) {
|
public ResponseContentEncoding(final Lookup<InputStreamFactory> decoderRegistry, final boolean ignoreUnknown) {
|
||||||
this.decoderRegistry = decoderRegistry != null ? decoderRegistry :
|
this.decoderRegistry = decoderRegistry != null ? decoderRegistry :
|
||||||
RegistryBuilder.<InputStreamFactory>create()
|
RegistryBuilder.<InputStreamFactory>create()
|
||||||
.register("gzip", GZIP)
|
.register("gzip", GZIP)
|
||||||
.register("x-gzip", GZIP)
|
.register("x-gzip", GZIP)
|
||||||
.register("deflate", DEFLATE)
|
.register("deflate", DEFLATE)
|
||||||
.build();
|
.build();
|
||||||
|
this.ignoreUnknown = ignoreUnknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 4.5
|
||||||
|
*/
|
||||||
|
public ResponseContentEncoding(final boolean ignoreUnknown) {
|
||||||
|
this(null, ignoreUnknown);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 4.4
|
||||||
|
*/
|
||||||
|
public ResponseContentEncoding(final Lookup<InputStreamFactory> decoderRegistry) {
|
||||||
|
this(decoderRegistry, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,7 +142,7 @@ public class ResponseContentEncoding implements HttpResponseInterceptor {
|
||||||
response.removeHeaders("Content-Encoding");
|
response.removeHeaders("Content-Encoding");
|
||||||
response.removeHeaders("Content-MD5");
|
response.removeHeaders("Content-MD5");
|
||||||
} else {
|
} else {
|
||||||
if (!"identity".equals(codecname)) {
|
if (!"identity".equals(codecname) && !ignoreUnknown) {
|
||||||
throw new HttpException("Unsupported Content-Coding: " + codec.getName());
|
throw new HttpException("Unsupported Content-Coding: " + codec.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,7 +151,7 @@ public class TestResponseContentEncoding {
|
||||||
response.setEntity(original);
|
response.setEntity(original);
|
||||||
final HttpContext context = new BasicHttpContext();
|
final HttpContext context = new BasicHttpContext();
|
||||||
|
|
||||||
final HttpResponseInterceptor interceptor = new ResponseContentEncoding();
|
final HttpResponseInterceptor interceptor = new ResponseContentEncoding(false);
|
||||||
interceptor.process(response, context);
|
interceptor.process(response, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue