lib: noproxy support, match proxy detection to request

PR-URL: https://github.com/nodejs/node-gyp/pull/1978
Reviewed-By: Rod Vagg <rod@vagg.org>
This commit is contained in:
Matias Lopez 2019-11-27 19:40:00 -05:00 committed by Rod Vagg
parent 345c70e56d
commit 3bcba2a01a
No known key found for this signature in database
GPG key ID: C273792F7D83545D
5 changed files with 192 additions and 5 deletions

View file

@ -90,6 +90,101 @@ test('download over https with custom ca', function (t) {
})
})
test('download over http with proxy', function (t) {
t.plan(2)
var server = http.createServer(function (req, res) {
t.strictEqual(req.headers['user-agent'],
'node-gyp v42 (node ' + process.version + ')')
res.end('ok')
pserver.close(function () {
server.close()
})
})
var pserver = http.createServer(function (req, res) {
t.strictEqual(req.headers['user-agent'],
'node-gyp v42 (node ' + process.version + ')')
res.end('proxy ok')
server.close(function () {
pserver.close()
})
})
var host = 'localhost'
server.listen(0, host, function () {
var port = this.address().port
pserver.listen(port + 1, host, function () {
var gyp = {
opts: {
proxy: 'http://' + host + ':' + (port + 1)
},
version: '42'
}
var url = 'http://' + host + ':' + port
var req = install.test.download(gyp, {}, url)
req.on('response', function (res) {
var body = ''
res.setEncoding('utf8')
res.on('data', function (data) {
body += data
})
res.on('end', function () {
t.strictEqual(body, 'proxy ok')
})
})
})
})
})
test('download over http with noproxy', function (t) {
t.plan(2)
var server = http.createServer(function (req, res) {
t.strictEqual(req.headers['user-agent'],
'node-gyp v42 (node ' + process.version + ')')
res.end('ok')
pserver.close(function () {
server.close()
})
})
var pserver = http.createServer(function (req, res) {
t.strictEqual(req.headers['user-agent'],
'node-gyp v42 (node ' + process.version + ')')
res.end('proxy ok')
server.close(function () {
pserver.close()
})
})
var host = 'localhost'
server.listen(0, host, function () {
var port = this.address().port
pserver.listen(port + 1, host, function () {
var gyp = {
opts: {
proxy: 'http://' + host + ':' + (port + 1),
noproxy: 'localhost'
},
version: '42'
}
var url = 'http://' + host + ':' + port
var req = install.test.download(gyp, {}, url)
req.on('response', function (res) {
var body = ''
res.setEncoding('utf8')
res.on('data', function (data) {
body += data
})
res.on('end', function () {
t.strictEqual(body, 'ok')
})
})
})
})
})
test('download with missing cafile', function (t) {
t.plan(1)
var gyp = {