How to use tunnel-agent - 10 common examples

To help you get started, we’ve selected a few tunnel-agent examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aliyun-node / commands / uploader.js View on Github external
var shasum = crypto.createHash('sha1');
  shasum.update([process.env.agentid || os.hostname(), token, nonce, id].join(''));
  var sign = shasum.digest('hex');

  var url = 'http://' + server + '/files/' + id + '?nonce=' + nonce + '&sign=' + sign + '&type=' + type;

  var gateway = process.env.GATEWAY;
  if (gateway) {
    // upload to gateway
    url = 'http://' + gateway + '/file?target=' + encodeURIComponent(url);
  }

  var agent = false;
  if (process.env.http_proxy) {
    var parts = process.env.http_proxy.split(':');
    agent = tunnel.httpOverHttp({
      proxy: {
        host: parts[0],
        port: parts[1]
      }
    });
  }

  var opts = {
    dataType: 'json',
    type: 'POST',
    timeout: 60000 * 20, // 20分钟超时
    headers: form.headers(),
    stream: form,
    agent: agent
  };
github qiniu / nodejs-sdk / examples / http_https_proxy.js View on Github external
var uploadToken = putPolicy.uploadToken(mac);
var config = new qiniu.conf.Config();
// config.zone = qiniu.zone.Zone_z0;
// config.useHttpsDomain = true;
var formUploader = new qiniu.form_up.FormUploader(config);
var putExtra = new qiniu.form_up.PutExtra();

// 设置HTTP(s)代理服务器,这里可以参考:https://github.com/request/tunnel-agent
// 有几个方法:
// exports.httpOverHttp = httpOverHttp
// exports.httpsOverHttp = httpsOverHttp
// exports.httpOverHttps = httpOverHttps
// exports.httpsOverHttps = httpsOverHttps

var proxyAgent = tunnel.httpOverHttp({
    proxy: {
        host: 'localhost',
        port: 8888
    }
});

qiniu.conf.RPC_HTTP_AGENT = proxyAgent;

// qiniu.conf.RPC_HTTPS_AGENT = proxyAgent;
// 以代理方式上传
formUploader.put(uploadToken, null, 'hello', putExtra, function (respErr,
    respBody, respInfo) {
    if (respErr) {
        throw respErr;
    }
github wuchangming / node-mitmproxy / src / common / util.js View on Github external
var hostname = urlObject.hostname || 'localhost';

    if (requestIsSSL) {
        if (protocol === 'http:') {
            if (!httpsOverHttpAgent) {
                httpsOverHttpAgent = tunnelAgent.httpsOverHttp({
                    proxy: {
                        host: hostname,
                        port: port
                    }
                });
            }
            return httpsOverHttpAgent
        } else {
            if (!httpsOverHttpsAgent) {
                httpsOverHttpsAgent = tunnelAgent.httpsOverHttps({
                    proxy: {
                        host: hostname,
                        port: port
                    }
                });
            }
            return httpsOverHttpsAgent
        }
    } else {
        if (protocol === 'http:') {
            // if (!httpOverHttpAgent) {
            //     httpOverHttpAgent = tunnelAgent.httpOverHttp({
            //         proxy: {
            //             host: hostname,
            //             port: port
            //         }
github wuchangming / node-mitmproxy / src / common / util.js View on Github external
return httpsOverHttpsAgent
        }
    } else {
        if (protocol === 'http:') {
            // if (!httpOverHttpAgent) {
            //     httpOverHttpAgent = tunnelAgent.httpOverHttp({
            //         proxy: {
            //             host: hostname,
            //             port: port
            //         }
            //     });
            // }
            return false
        } else {
            if (!httpOverHttpsAgent) {
                httpOverHttpsAgent = tunnelAgent.httpOverHttps({
                    proxy: {
                        host: hostname,
                        port: port
                    }
                });
            }
            return httpOverHttpsAgent
        }
    }
}
github algolia / algoliasearch-client-javascript / test / run-integration.js View on Github external
server.listen(0, function() {
    var tunnel = require('tunnel-agent');

    var agentSettings = {
      proxy: {
        host: server.address().host,
        port: server.address().port
      }
    };

    var proxyClient = algoliasearch(appId, apiKey, {
      httpAgent: tunnel.httpsOverHttp(agentSettings)
    });
    var proxyIndex = proxyClient.initIndex(indexName);
    proxyIndex
      .browse()
      .then(end)
      .then(null, _.bind(t.error, t));

    function end(content) {
      server.close();
      proxyClient.destroy();
      t.ok(content.hits.length, 'We got some content');
    }
  });
}
github DevExpress / testcafe-hammerhead / src / request-pipeline / destination-request / agent.ts View on Github external
export function assign (reqOpts: RequestOptions): void {
    const proxy = reqOpts.proxy;

    if (proxy && reqOpts.protocol === 'https:') {
        reqOpts.agent = tunnel.httpsOverHttp({
            proxy,
            rejectUnauthorized: false
        });

        return;
    }

    let type = '';

    if (reqOpts.protocol === 'http:')
        type = TYPE.HTTP;

    else if (ssl3HostCache.get(reqOpts.host))
        type = TYPE.SSL3;

    else
github faye / faye / src / transport / node_http.js View on Github external
}

    var options = assign({
      proxy: {
        host:       this._proxyUri.hostname,
        port:       this._proxyUri.port || this.DEFAULT_PORTS[this._proxyUri.protocol],
        proxyAuth:  this._proxyUri.auth,
        headers:    assign({ host: this.endpoint.host }, proxy.headers)
      }
    }, this._dispatcher.tls);

    if (this._proxySecure) {
      assign(options.proxy, proxy.tls);
      this._tunnel = tunnel.httpsOverHttps(options);
    } else {
      this._tunnel = tunnel.httpsOverHttp(options);
    }
  },
github heroku / cli / packages / heroku-local / lib / download.js View on Github external
return new Promise(function (fulfill, reject) {
    let httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy;
    let agent;
    if (httpsProxy) {
      cli.hush(`proxy set to ${httpsProxy}`);
      let proxy = url.parse(httpsProxy);

      agent = tunnel.httpsOverHttp({
        proxy: {
          host: proxy.hostname,
          port: proxy.port || 8080
        }
      });
    } else {
      agent = new https.Agent();
    }

    let requestOptions = url.parse(urlStr);
    requestOptions.agent = agent;

    let req = https.request(requestOptions, function (res) {
      if (res.statusCode > 200 || res.statusCode >= 300) return reject(new Error(res.body));
      res.pipe(fs.createWriteStream(tmpPath, opts));
      res.on('end', fulfill);
github wuchangming / node-mitmproxy / src / common / util.js View on Github external
util.getTunnelAgent = (requestIsSSL, externalProxyUrl) => {
    var urlObject = url.parse(externalProxyUrl);
    var protocol = urlObject.protocol || 'http:';
    var port = urlObject.port;
    if (!port) {
        port = protocol === 'http:' ? 80 : 443;
    }
    var hostname = urlObject.hostname || 'localhost';

    if (requestIsSSL) {
        if (protocol === 'http:') {
            if (!httpsOverHttpAgent) {
                httpsOverHttpAgent = tunnelAgent.httpsOverHttp({
                    proxy: {
                        host: hostname,
                        port: port
                    }
                });
            }
            return httpsOverHttpAgent
        } else {
            if (!httpsOverHttpsAgent) {
                httpsOverHttpsAgent = tunnelAgent.httpsOverHttps({
                    proxy: {
                        host: hostname,
                        port: port
                    }
                });
            }
github cnpm / cnpmjs.org / common / urllib.js View on Github external
var config = require('../config');

var httpAgent;
var httpsAgent;

if (config.httpProxy) {
  var tunnel = require('tunnel-agent');
  var urlinfo = urlparse(config.httpProxy);
  if (urlinfo.protocol === 'http:') {
    httpAgent = tunnel.httpOverHttp({
      proxy: {
        host: urlinfo.hostname,
        port: urlinfo.port
      }
    });
    httpsAgent = tunnel.httpsOverHttp({
      proxy: {
        host: urlinfo.hostname,
        port: urlinfo.port
      }
    });
  } else if (urlinfo.protocol === 'https:') {
    httpAgent = tunnel.httpOverHttps({
      proxy: {
        host: urlinfo.hostname,
        port: urlinfo.port
      }
    });
    httpsAgent = tunnel.httpsOverHttps({
      proxy: {
        host: urlinfo.hostname,
        port: urlinfo.port

tunnel-agent

HTTP proxy tunneling agent. Formerly part of mikeal/request, now a standalone module.

Apache-2.0
Latest version published 8 years ago

Package Health Score

71 / 100
Full package analysis