/** * Usage example of the `HttpProxyAgent` class proxying an HTTP endpoint. */ var url = require('url'); var http = require('http'); var HttpProxyAgent = require('./http-proxy-agent'); // HTTP proxy to connect to var proxy = process.env.http_proxy || 'http://168.63.76.32:3128'; console.log('using proxy server %j', proxy); proxy = url.parse(proxy); // HTTP endpoint for the proxy to connect to var endpoint = process.argv[2] || 'http://nodejs.org/api/'; console.log('attempting to GET %j', endpoint); var opts = url.parse(endpoint); // create an instance of the `HttpProxyAgent` class with the proxy server information var agent = new HttpProxyAgent(proxy); opts.agent = agent; http.get(opts, function (res) { console.log('"response" event!', res.headers); res.pipe(process.stdout); });