GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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
Filter options
  • lib
    • _http_client.js
    • https.js
  • test/parallel
    • test-http-invalid-urls.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/_http_client.js‎

Copy file name to clipboardExpand all lines: lib/_http_client.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ function ClientRequest(options, cb) {
2222

2323
if (typeof options === 'string') {
2424
options = url.parse(options);
25+
if (!options.hostname) {
26+
throw new Error('Unable to determine the domain name');
27+
}
2528
} else {
2629
options = util._extend({}, options);
2730
}
Collapse file

‎lib/https.js‎

Copy file name to clipboardExpand all lines: lib/https.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ exports.Agent = Agent;
156156
exports.request = function(options, cb) {
157157
if (typeof options === 'string') {
158158
options = url.parse(options);
159+
if (!options.hostname) {
160+
throw new Error('Unable to determine the domain name');
161+
}
159162
} else {
160163
options = util._extend({}, options);
161164
}
Collapse file

‎test/parallel/test-http-invalid-urls.js‎

Copy file name to clipboard
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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);

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.