Reusable server url

Improve the re-usability of the addQueryArg() method

- Support SSL protocol
- Make the serverUrl code re-usable
I Intentionally didn't change the code style of this function as it's taken one-on-one from the WP core codebase. Not changing the code style makes it easier to compare for changes.
Sorry, should have mentioned the source in the comment.