mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
http{s}: don't connect to localhost on invalid URL
If the URL passed to `http{s}.request` or `http{s}.get` is not properly
parsable by `url.parse`, we fall back to use `localhost` and port 80.
This creates confusing error messages like in this question
http://stackoverflow.com/q/32675907/1903116.
This patch throws an error message, if `url.parse` fails to parse the
URL properly.
Previous Discussion: https://github.com/nodejs/node/pull/2966
PR-URL: https://github.com/nodejs/node/pull/2967
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
6a04cc0a43
commit
c9786bb680
3 files changed
+25
No files matched your search
@@ -163,6 +163,9 @@ exports.Agent = Agent;
|
||||
exports.request = function(options, cb) {
|
||||
if (typeof options === 'string') {
|
||||
options = url.parse(options);
|
||||
if (!options.hostname) {
|
||||
throw new Error('Unable to determine the domain name');
|
||||
}
|
||||
} else {
|
||||
options = util._extend({}, options);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user