I run a couple of times into situations where I need to change the URI a little bit. It ends up as a mess of if/else-s because the urls can have different protocols, may or may not contain a user and port, may have params, etc.
I propose a function `construct_uri(protocol, user, domain, port, params)` which returns a URI based on those arguments. The user, port, params parts should be optional, so it should be legal to call:
construct_uri("sip", null, "18.104.22.168", null, null) -> "sip:22.214.171.124"
construct_uri("sip", $rU, $rd, null, "key=val") -> "sip:$rU@$rd;key=val" (with expanded vars of course)