mikeal/request — pull request #1138 by cappslock (2014-10-09 16:08:26+00:00)
Title: allow hostname and port in place of host on uri

This is an issue I noticed in 2.45.0 that was not present in 2.44.0. I passed in a URL of this format:

```
{
hostname: "whatever.com",
port: 8080,
path: "/something"
protocol: "http:"
}
```

It fails [here][https://github.com/mikeal/request/blob/master/request.js#L246], in this block:

```
if (!self.uri.host && self.uri.protocol !== 'unix:') {
// Invalid URI: it may generate lot of bad errors, like 'TypeError: Cannot call method `indexOf` of undefined' in CookieJar
// Detect and reject it as soon as possible
var faultyUri = url.format(self.uri)
var message = 'Invalid URI "' + faultyUri + '"'
if (Object.keys(options).length === 0) {
// No option ? This can be the sign of a redirect
// As this is a case where the user cannot do anything (they didn't call request directly with this URL)
// they should be warned that it can be caused by a redirection (can save some hair)
message += '. This can be caused by a crappy redirection.'
}
// This error was fatal
return self.emit('error', new Error(message))
}
```

But based on [node's URL format][http://nodejs.org/api/url.html#url_url_format_urlobj], using `hostname` and `port` should be an acceptable alternative to using `host`.

This is easy enough to work around by formatting the url before passing it in, but this pull request resolves the issue and passes unit tests. Happy to rework it if there are any issues.