On Thu, 2014-01-09 at 13:34 -0800, Gaurav Kumar wrote:
> In my use case, I need to know on per request basis what was the encoding
> used by remote server. I was hoping there there was out of the box way to
> know content-encoding but I am okay with disabling decompression. Thanks
> for the suggestion.
>
>
You do not have to disable it. You can still use a custom protocol
interceptor to get the job done.
---
CloseableHttpClient httpclient = HttpClients.custom()
.addInterceptorFirst(new HttpResponseInterceptor() {
@Override
public void process(
HttpResponse response,
HttpContext context) throws HttpException,
IOException {
HttpEntity entity = response.getEntity();
if (entity != null && entity.getContentLength() != 0) {
Header ceheader = entity.getContentEncoding();
if (ceheader != null) {
context.setAttribute("mystuff",
ceheader.getValue());
}
}
}
}).build();
HttpClientContext context = HttpClientContext.create();
CloseableHttpResponse response = httpclient.execute(new
HttpGet("/stuff"), context);
try {
String originalEncoding = context.getAttribute("mystuff",
String.class);
} finally {
response.close();
}
---
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]