Allow users to override connection keep alive logic

Implements #733 for 1.9.x.