I don't think so, in case of port 443 or 80 this code drops the port.
My suggestion however is to drop the port entirely at this point, because guessing the repository port from the api port is not a good practice to start with. To properly support this feature, we should get the full url of the repository from pulp server.