Extract scheme/host/port extraction to a separate function, take https into consideration when deciding whether to add extra port or not