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

Bad Apache HttpClient example #28

@slisaasquatch

Description

@slisaasquatch

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions