if (conn != null && !conn.isOpen())
return false;
// do NOT check for stale connection, that is an expensive operation
HttpEntity entity = response.getEntity();
HttpVersion ver = response.getStatusLine().getHttpVersion();
if (entity != null) {
if (entity.getContentLength() < 0) {
if (!entity.isChunked() || ver.lessEquals(HttpVersion.HTTP_1_0)) {
// if the content length is not known and is not chunk
// encoded, the connection cannot be reused
return false;
}
}
}
// Check for 'Connection' directive
Header connheader = response.getFirstHeader(HTTP.CONN_DIRECTIVE);
if (connheader != null) {
String conndirective = connheader.getValue();
if (HTTP.CONN_CLOSE.equalsIgnoreCase(conndirective)) {
return false;
} else if (HTTP.CONN_KEEP_ALIVE.equalsIgnoreCase(conndirective)) {
return true;
} else {
// log unknown directive
}
}
// Resorting to protocol version default close connection policy
return ver.greaterEquals(HttpVersion.HTTP_1_1);
}