Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7f04377

Browse filesBrowse files
edsadrItalo A. Casas
authored andcommitted
test: improve code in test-http-host-headers
* use common.fail to handle errors * remove console.log * use arrow functions PR-URL: #10830 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 66c57a2 commit 7f04377
Copy full SHA for 7f04377

File tree

Expand file treeCollapse file tree

1 file changed

+12
-25
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-25
lines changed
Open diff view settings
Collapse file
+12-25Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const http = require('http');
44
const assert = require('assert');
55
const httpServer = http.createServer(reqHandler);
66

77
function reqHandler(req, res) {
8-
console.log('Got request: ' + req.headers.host + ' ' + req.url);
98
if (req.url === '/setHostFalse5') {
109
assert.strictEqual(req.headers.host, undefined);
1110
} else {
@@ -14,14 +13,9 @@ function reqHandler(req, res) {
1413
req.headers.host);
1514
}
1615
res.writeHead(200, {});
17-
//process.nextTick(function() { res.end('ok'); });
1816
res.end('ok');
1917
}
2018

21-
function thrower(er) {
22-
throw er;
23-
}
24-
2519
testHttp();
2620

2721
function testHttp() {
@@ -30,59 +24,52 @@ function testHttp() {
3024

3125
function cb(res) {
3226
counter--;
33-
console.log('back from http request. counter = ' + counter);
3427
if (counter === 0) {
3528
httpServer.close();
3629
}
3730
res.resume();
3831
}
3932

40-
httpServer.listen(0, function(er) {
41-
console.error(`test http server listening on ${this.address().port}`);
33+
httpServer.listen(0, (er) => {
4234
assert.ifError(er);
4335
http.get({
4436
method: 'GET',
4537
path: '/' + (counter++),
4638
host: 'localhost',
47-
//agent: false,
48-
port: this.address().port,
39+
port: httpServer.address().port,
4940
rejectUnauthorized: false
50-
}, cb).on('error', thrower);
41+
}, cb).on('error', common.fail);
5142

5243
http.request({
5344
method: 'GET',
5445
path: '/' + (counter++),
5546
host: 'localhost',
56-
//agent: false,
57-
port: this.address().port,
47+
port: httpServer.address().port,
5848
rejectUnauthorized: false
59-
}, cb).on('error', thrower).end();
49+
}, cb).on('error', common.fail).end();
6050

6151
http.request({
6252
method: 'POST',
6353
path: '/' + (counter++),
6454
host: 'localhost',
65-
//agent: false,
66-
port: this.address().port,
55+
port: httpServer.address().port,
6756
rejectUnauthorized: false
68-
}, cb).on('error', thrower).end();
57+
}, cb).on('error', common.fail).end();
6958

7059
http.request({
7160
method: 'PUT',
7261
path: '/' + (counter++),
7362
host: 'localhost',
74-
//agent: false,
75-
port: this.address().port,
63+
port: httpServer.address().port,
7664
rejectUnauthorized: false
77-
}, cb).on('error', thrower).end();
65+
}, cb).on('error', common.fail).end();
7866

7967
http.request({
8068
method: 'DELETE',
8169
path: '/' + (counter++),
8270
host: 'localhost',
83-
//agent: false,
84-
port: this.address().port,
71+
port: httpServer.address().port,
8572
rejectUnauthorized: false
86-
}, cb).on('error', thrower).end();
73+
}, cb).on('error', common.fail).end();
8774
});
8875
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.