How to use the tunnel.httpsOverHttp function in tunnel

To help you get started, we’ve selected a few tunnel 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 slackapi / node-slack-sdk / examples / incoming-webhook-with-proxy.js View on Github external
const { IncomingWebhook } = require('../dist');

// Get a URL by creating an app at , and configuring an Incoming Webhook
// It's always a good idea to keep sensitive data like the url outside your source code. Prefer environment variables.
const url = process.env.SLACK_WEBHOOK_URL || '';

if (!url) { console.log('You must specify a webhook url to use this example'); process.exitCode = 1; return; }

const proxyUrl = process.env.SLACK_PROXY_URL || '';
const proxyPort = process.env.SLACK_PROXY_PORT || '';
const proxyScheme = process.env.SLACK_PROXY_SCHEME || 'http';
const proxyEndpoint = `${proxyScheme}://${proxyUrl}:${proxyPort}`;

// Initialize a custom agent for an HTTP proxy
const tunnel = require('tunnel');
const tunnelAgent = tunnel.httpsOverHttp({
  proxy: {
    host: proxyUrl,
    port: proxyPort
  }
});

// Initialize the IncomingWebhook using the custom agent
const webhookTunnelAgent = new IncomingWebhook(url, { agent: tunnelAgent } );

// Send IncomingWebhook Message over tunnel
sendWebhookMessage(webhookTunnelAgent, 'Hello World, over tunnel agent!');

// Initialize a custom agent again, but this time using a different package
const HttpsProxyAgent = require('https-proxy-agent');
const httpsProxyAgent = new HttpsProxyAgent(proxyEndpoint);
github HPSoftware / node-offline-debug / lib / network.js View on Github external
var headers = (optionalHeaders != null ? optionalHeaders : {});
        headers.Authorization = auth;

        if (proxy != null)
        {
            match = proxy.match(/^(http:\/\/)?([^:\/]+)(:([0-9]+))?/i);
            /*
            if (match) {
                    host = match[2];
                    port = (match[4] != null ? match[4] : 80);
                    path = "https://" + config.url + url;
                    headers.Host = config.url;
            }
            */
            tunnelingAgent = tunnel.httpsOverHttp({
              proxy: { // Proxy settings
                host: match[2],
                port: (match[4] != null ? match[4] : 80),
                rejectUnauthorized : false
              }
            });

        }

        var options = {
            "port": port,
            "host": host,
            "path": path,
            "method": method,
            "headers": headers,
            "rejectUnauthorized": false,
github wuchengwei / node-wget / lib / wget.js View on Github external
} else if (options.proxy.protocol === 'https') {
                delete options.proxy.protocol; // delete self-defined arg
                options.agent = tunnel.httpOverHttps({proxy: options.proxy});
            } else {
                throw options.proxy.protocol + ' proxy is not supported!';
            }
        }
        delete options.protocol; // delete self-defined arg
        delete options.proxy; // delete self-defined arg
        return http.request(options, callback);
    }
    if (options.protocol === 'https') {
        if (options.proxy) {
            if (options.proxy.protocol === 'http') {
                delete options.proxy.protocol; // delete self-defined arg
                options.agent = tunnel.httpsOverHttp({proxy: options.proxy});
            } else if (options.proxy.protocol === 'https') {
                delete options.proxy.protocol; // delete self-defined arg
                options.agent = tunnel.httpsOverHttps({proxy: options.proxy});
            } else {
                throw options.proxy.protocol + ' proxy is not supported!';
            }
        }
        delete options.protocol; // delete self-defined arg
        delete options.proxy; // delete self-defined arg
        return https.request(options, callback);
    }
    throw 'only allow http or https request!';
}
github np-maintain / global-tunnel / index.js View on Github external
if (useCONNECT) {
    if (conf.proxyHttpsOptions) {
      assign(opts.proxy, conf.proxyHttpsOptions);
    }
    if (conf.originHttpsOptions) {
      assign(opts, conf.originHttpsOptions);
    }

    if (outerProtocol === 'https:') {
      if (innerProtocol === 'https:') {
        return tunnel.httpsOverHttps(opts);
      }
      return tunnel.httpOverHttps(opts);
    }
    if (innerProtocol === 'https:') {
      return tunnel.httpsOverHttp(opts);
    }
    return tunnel.httpOverHttp(opts);
  }
  if (conf.originHttpsOptions) {
    throw new Error('originHttpsOptions must be combined with a tunnel:true option');
  }
  if (conf.proxyHttpsOptions) {
    // NB: not opts.
    assign(opts, conf.proxyHttpsOptions);
  }

  if (outerProtocol === 'https:') {
    return new agents.OuterHttpsAgent(opts);
  }
  return new agents.OuterHttpAgent(opts);
};
github Azure / ms-rest-js / lib / axiosHttpClient.ts View on Github external
export function createTunnel(isRequestHttps: boolean, isProxyHttps: boolean, tunnelOptions: tunnel.HttpsOverHttpsOptions): http.Agent | https.Agent {
  if (isRequestHttps && isProxyHttps) {
    return tunnel.httpsOverHttps(tunnelOptions);
  } else if (isRequestHttps && !isProxyHttps) {
    return tunnel.httpsOverHttp(tunnelOptions);
  } else if (!isRequestHttps && isProxyHttps) {
    return tunnel.httpOverHttps(tunnelOptions);
  } else {
    return tunnel.httpOverHttp(tunnelOptions);
  }
}
github hainproject / hain / app / main / worker / global-proxy-agent.js View on Github external
function createHttpsProxyAgent(host, port) {
  return tunnel.httpsOverHttp({
    proxy: { host, port }
  });
}
github Azure / azure-sdk-for-java / ClientRuntimes / NodeJS / ms-rest / lib / filters / proxyFilter.js View on Github external
proxy: proxy
    };

    if (resource.key) {
      agentinfo.key = resource.key;
    }
    if (resource.cert) {
      agentinfo.cert = resource.cert;
    }

    var isOverHTTPS = utils.urlIsHTTPS(proxy);
    if (isHTTPS) {
      if (isOverHTTPS) {
        resource.agent = tunnel.httpsOverHttps(agentinfo);
      } else {
        resource.agent = tunnel.httpsOverHttp(agentinfo);
      }
    } else {
      if (isOverHTTPS) {
        resource.agent = tunnel.httpOverHttps(agentinfo);
      } else {
        resource.agent = tunnel.httpOverHttp(agentinfo);
      }
    }
  } else if (isHTTPS) {
    resource.agent = new https.Agent(resource);
  }
};
github alphagov / pay-selfservice / app / utils / proxy.js View on Github external
https.request = function (options, callback) {
        if (typeof options === 'string') {
          options = urlParse(options)
        }

        if (shouldProxy(options)) {
          options.agent = tunnel.httpsOverHttp({
            proxy: { host: httpsProxy.hostname, port: httpsProxy.port },
            ca: https.globalAgent.options.ca
          })
        }

        return originalHttpsRequest.call(this, options, callback)
      }
    }

tunnel

Node HTTP/HTTPS Agents for tunneling proxies

MIT
Latest version published 6 years ago

Package Health Score

55 / 100
Full package analysis