Fix #1987. First, res may be null if we have an error with a URL. Second, if the URL has no protocol, use http