protected void setStrategiesForClient(HttpAsyncClientBuilder client) {
final long keepAlive = configuration.getKeepAlive().toMilliseconds();
// don't keep alive the HTTP connection and thus don't reuse the TCP socket
if (keepAlive == 0) {
client.setConnectionReuseStrategy(new NoConnectionReuseStrategy());
} else {
client.setConnectionReuseStrategy(new DefaultConnectionReuseStrategy());
// either keep alive based on response header Keep-Alive,
// or if the server can keep a persistent connection (-1), then override based on client's configuration
client.setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy() {