Skip to content
This repository has been archived by the owner on Apr 22, 2020. It is now read-only.

Bad Apache HttpClient example #28

Open
slisaasquatch opened this issue Feb 21, 2019 · 0 comments
Open

Bad Apache HttpClient example #28

slisaasquatch opened this issue Feb 21, 2019 · 0 comments

Comments

@slisaasquatch
Copy link

What I'm talking about is this file.

The example doesn't just unnecessarily implement things like HttpRequestInterceptor and HttpResponseInterceptor, it will actually disable Apache HttpClient's built-in content encoding support, namely gzip and deflate.

This is all you need to do:

final LinkedHashMap<String, InputStreamFactory> contentDecoderMap = new LinkedHashMap<>();
contentDecoderMap.put("br", new InputStreamFactory() {
	@Override
	public InputStream create(InputStream inStream) throws IOException {
		return new BrotliInputStream(inStream);
	}
});
contentDecoderMap.put("gzip", GZIPInputStreamFactory.getInstance());
contentDecoderMap.put("x-gzip", GZIPInputStreamFactory.getInstance());
contentDecoderMap.put("deflate", DeflateInputStreamFactory.getInstance());
try (CloseableHttpClient httpClient = HttpClients.custom()
		.setContentDecoderRegistry(contentDecoderMap)
		.build()) {
	//...
}

And everything else will be handled by HttpClient automatically.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant