Refactoring api optional ssl logic