self.agent can and will be a non-object so this needs to be checked

The current version throws an exception when used with options { agent:false } because globalAgent is undefined.

This is really just a kludge. The real issue is that the whole agent:false thing is documented and has been broken, fixed and rebroken too many times.

Because if I choose not to use an agent, the default port should come from the protocol and not from the globalAgent. There is an assumption in there somewhere that there will be an agent and that it will be the HTTP or HTTPS agent, which is just not true by design.