server.listen(0, common.mustCall(() => {
   const port = server.address().port;
   const host = 'localhost';
   const options = {
     rejectUnauthorized: false,
     _agentKey: agent.getName({
       port: port,
       host: host,
     }),
   };
   const socket = agent.createConnection(port, host, options);
   checkRequest(socket, server);
 }));
Ejemplo n.º 2
0
// HttpsProxyAgent for handling proxying
function HttpsProxyAgent(options) {
    https.Agent.call(this, options);
 
    this.proxyHost = options.proxyHost;
    this.proxyPort = options.proxyPort;
 
    this.createConnection = function (opts, callback) {
        // do a CONNECT request
        var req = http.request({
            host    : options.proxyHost,
            port    : options.proxyPort,
            method  : 'CONNECT',
            path    : opts.host + ':' + opts.port,
            headers : {
                host: opts.host
            }
        });
 
        req.on('connect', function (res, socket, head) {
            var cts = Tls.connect({
                host: opts.host,
                socket: socket
            }, function () {
                callback(false, cts);
            });
        });
 
        req.on('error', function (err) {
            callback(err, null);
        });
 
        req.end();
    };
}
 server.listen(0, common.mustCall(() => {
   const port = server.address().port;
   const host = 'localhost';
   const options = undefined;
   const socket = agent.createConnection(port, host, options);
   socket.on('error', common.mustCall((e) => {
     assert(expectCertError.test(e.toString()));
     server.close();
   }));
 }));
Ejemplo n.º 4
0
 it('should send a request using the custom agent', function () {
   const agent = new Agent({ keepAlive: true });
   const spy = sinon.spy(agent, 'addRequest');
   const client = new WebClient(token, { agent, retryConfig: rapidRetryPolicy });
   return client.apiCall('method')
     .catch(() => {
       assert(spy.called);
     })
     .then(() => {
       agent.addRequest.restore();
       agent.destroy();
     })
     .catch((error) => {
       agent.addRequest.restore();
       agent.destroy();
       throw error;
     });
 });
Ejemplo n.º 5
0
 .catch((error) => {
   agent.addRequest.restore();
   agent.destroy();
   throw error;
 });
Ejemplo n.º 6
0
 .then(() => {
   agent.addRequest.restore();
   agent.destroy();
 })
Ejemplo n.º 7
0
'use strict';

const common = require('../common');
if (!common.hasCrypto)
  common.skip('missing crypto');

const assert = require('assert');
const https = require('https');

const agent = new https.Agent();

// empty options
assert.strictEqual(
  agent.getName({}),
  'localhost:::::::::::::::::'
);

// pass all options arguments
const options = {
  host: '0.0.0.0',
  port: 443,
  localAddress: '192.168.1.1',
  ca: 'ca',
  cert: 'cert',
  ciphers: 'ciphers',
  crl: [Buffer.from('c'), Buffer.from('r'), Buffer.from('l')],
  dhparam: 'dhparam',
  ecdhCurve: 'ecdhCurve',
  honorCipherOrder: false,
  key: 'key',
  pfx: 'pfx',
Ejemplo n.º 8
0
 afterEach(function () {
   https.Agent.restore();
 });