-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
set-host.js
46 lines (40 loc) · 1.11 KB
/
set-host.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
const request = require('../support/client');
const express = require('../support/express');
const app = express();
const http = require('http');
const assert = require('assert');
describe('request.get().set()', () => {
if (process.env.HTTP2_TEST) {
return; // request object doesn't look the same
}
let server;
after(function exitServer() {
if (typeof server.close === 'function') {
server.close();
} else {
server.destroy();
}
});
it('should set host header after get()', (done) => {
app.get('/', (request_, res) => {
assert.equal(request_.hostname, 'example.com');
res.end();
});
server = http.createServer(app);
server.listen(0, function listening() {
request
.get(`http://localhost:${server.address().port}`)
.set('host', 'example.com')
.then(() => {
return request
.get(`http://example.com:${server.address().port}`)
.connect({
'example.com': 'localhost',
'*': 'fail'
});
})
.then(() => done(), done);
});
});
});