This logic for determining http/https is not fault-tolerant. It doesn't work for example when schemes is `array('foo', 'https')`.