GeezerVison is showing github.com — http{s}: don't connect to localhost on invalid URL · thefourtheye/io.js@4897c28
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/_http_client.js +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -22,6 +22,9 @@ function ClientRequest(options, cb) { |
22 | 22 |
|
23 | 23 | if (typeof options === 'string') { |
24 | 24 | options = url.parse(options); |
| 25 | + if (!options.hostname) { |
| 26 | + throw new Error('Unable to determine the domain name'); |
| 27 | + } |
25 | 28 | } else { |
26 | 29 | options = util._extend({}, options); |
27 | 30 | } |
|
Collapse file
Copy file name to clipboardExpand all lines: lib/https.js +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -156,6 +156,9 @@ exports.Agent = Agent; |
156 | 156 | exports.request = function(options, cb) { |
157 | 157 | if (typeof options === 'string') { |
158 | 158 | options = url.parse(options); |
| 159 | + if (!options.hostname) { |
| 160 | + throw new Error('Unable to determine the domain name'); |
| 161 | + } |
159 | 162 | } else { |
160 | 163 | options = util._extend({}, options); |
161 | 164 | } |
|
Collapse file
Copy file name to clipboard +19Lines changed: 19 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +require('../common'); |
| 4 | +const assert = require('assert'); |
| 5 | +const http = require('http'); |
| 6 | +const https = require('https'); |
| 7 | +const error = 'Unable to determine the domain name'; |
| 8 | + |
| 9 | +function test(host) { |
| 10 | + ['get', 'request'].forEach((method) => { |
| 11 | + [http, https].forEach((module) => { |
| 12 | + assert.throws(() => module[method](host, () => { |
| 13 | + throw new Error(`${module}.${method} should not connect to ${host}`); |
| 14 | + }), error); |
| 15 | + }); |
| 16 | + }); |
| 17 | +} |
| 18 | + |
| 19 | +['www.nodejs.org', 'localhost', '127.0.0.1', 'http://:80/'].forEach(test); |