JSPM

@doctormckay/proxy-agent

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 17
  • Score
    100M100P100Q17319F
  • License MIT

An HTTP Agent that connects to an HTTP proxy

Package Exports

  • @doctormckay/proxy-agent

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@doctormckay/proxy-agent) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ProxyAgent

This is a module which simply provides an HTTP(S) Agent which allows for requests/connections to be made through an HTTP(S) proxy.

Usage

ProxyAgent.getAgent(secure[, proxyUrl[, proxyTimeout]])

  • secure - true if this agent will be used for secure (HTTPS) requests, or false if not
  • proxyUrl - The URL to your proxy, or something falsy to just get false returned (indicating no agent)
  • proxyTimeout - The timeout for connecting to the proxy in milliseconds; default 5000 (5 seconds)
const ProxyAgent = require('@doctormckay/proxy-agent');
const HTTPS = require('https');

HTTPS.get({
    "host": "icanhazip.com",
    "port": 443,
    "agent": ProxyAgent.getAgent(true, "http://user:pass@1.2.3.4:12345", 10000)
}, (res) => {
    if (res.statusCode != 200) {
        console.log("HTTP error: " + res.statusCode);
    }
    
    res.on('data', (chunk) => {
        console.log(chunk.toString('utf8'));
    });
}).on('error', (err) => {
    console.log(err);
});