private static InputStream doExtractResponseBodyAsStream(InputStream is, Exchange exchange) throws IOException {
// As httpclient is using a AutoCloseInputStream, it will be closed when the connection is closed
// we need to cache the stream for it.
try {
// This CachedOutputStream will not be closed when the exchange is onCompletion
CachedOutputStream cos = new CachedOutputStream(exchange, false);
IOHelper.copy(is, cos);
// When the InputStream is closed, the CachedOutputStream will be closed
return cos.getWrappedInputStream();
} finally {
IOHelper.close(is, "Extracting response body", LOG);
}
}