Handling http/https switch correctly