Refactor ssl monkey patching and fix https tests.