finki-main
main
|
Last change
on this file since 81bc7da was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago |
|
Initial commit
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Rev | Line | |
|---|
| [81bc7da] | 1 | const url = require('url')
|
|---|
| 2 | const tunnel = require('tunnel-agent')
|
|---|
| 3 | const util = require('./util')
|
|---|
| 4 |
|
|---|
| 5 | function applyProxy (reqOpts, opts) {
|
|---|
| 6 | const log = opts.log || util.noopLogger
|
|---|
| 7 |
|
|---|
| 8 | const proxy = opts['https-proxy'] || opts.proxy
|
|---|
| 9 |
|
|---|
| 10 | if (proxy) {
|
|---|
| 11 | // eslint-disable-next-line node/no-deprecated-api
|
|---|
| 12 | const parsedDownloadUrl = url.parse(reqOpts.url)
|
|---|
| 13 | // eslint-disable-next-line node/no-deprecated-api
|
|---|
| 14 | const parsedProxy = url.parse(proxy)
|
|---|
| 15 | const uriProtocol = (parsedDownloadUrl.protocol === 'https:' ? 'https' : 'http')
|
|---|
| 16 | const proxyProtocol = (parsedProxy.protocol === 'https:' ? 'Https' : 'Http')
|
|---|
| 17 | const tunnelFnName = [uriProtocol, proxyProtocol].join('Over')
|
|---|
| 18 | reqOpts.agent = tunnel[tunnelFnName]({
|
|---|
| 19 | proxy: {
|
|---|
| 20 | host: parsedProxy.hostname,
|
|---|
| 21 | port: +parsedProxy.port,
|
|---|
| 22 | proxyAuth: parsedProxy.auth
|
|---|
| 23 | }
|
|---|
| 24 | })
|
|---|
| 25 | log.http('request', 'Proxy setup detected (Host: ' +
|
|---|
| 26 | parsedProxy.hostname + ', Port: ' +
|
|---|
| 27 | parsedProxy.port + ', Authentication: ' +
|
|---|
| 28 | (parsedProxy.auth ? 'Yes' : 'No') + ')' +
|
|---|
| 29 | ' Tunneling with ' + tunnelFnName)
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | return reqOpts
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | module.exports = applyProxy
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.