@VisibleForTesting
HttpResponse makeControlStreamRequest(HttpUriRequest request) throws IOException, ControlStreamException {
HttpResponse response = client.execute(request);
if (response.getStatusLine() == null) {
throw new ControlStreamException("No status line in response");
}
logger.debug("{} returned with status line: {}", request.getURI(), response.getStatusLine());
if (response.getStatusLine().getStatusCode() != HttpConstants.Codes.SUCCESS) {
logger.warn("{} returned with status code {}", request.getURI(), response.getStatusLine().getStatusCode());
if (response.getEntity() != null) {
// close the resources if the request failed. this might be redundant
EntityUtils.consume(response.getEntity());
}
throw new ControlStreamException(response.getStatusLine());
}
return response;
}