I have a requirement to set up an https proxy server(Secure Web Proxy-http://dev.chromium.org/developers/design-documents/secure-web-proxy) to test one of my application with the proxy environment.
Steps followed: 1.Created an https proxy server with the help of http-proxy. code,
var https = require('https'),
http = require('http'),
util = require('util'),
fs = require('fs'),
path = require('path'),
colors = require('colors'),
httpProxy = require('http-proxy'),
// fixturesDir = path.join(__dirname, '..', '..', 'test', 'fixtures'),
httpsOpts = {
key: fs.readFileSync('server.key', 'utf8'),
cert: fs.readFileSync('server.crt', 'utf8')
};
//
// Create the target HTTPS server
//
https.createServer(httpsOpts, function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('hello https\n');
res.end();
}).listen(9010);
//
// Create the proxy server listening on port 8010
//
httpProxy.createServer({
ssl: httpsOpts,
target: 'https://localhost:9010',
secure: false
}).listen(8010);
console.log('https proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8010'.yellow);
console.log('https server '.blue + 'started '.green.bold + 'on port '.blue + '9010 '.yellow);
- Created a PAC file with https proxy server details
function FindProxyForURL(url, host) { return "HTTPS 127.0.0.1:8010"; }
- And point the pac file in my application to test application with proxy environment, sample code pasted here.
var url = require('url'); var https = require('https'); var PacProxyAgent = require('pac-proxy-agent'); // URI to a PAC proxy file to use (the "pac+" prefix is stripped) var proxy = 'pac+http://localhost:123/hosted/pac.pac'; //console.log('using PAC proxy proxy file at %j', proxy); // HTTP endpoint for the proxy to connect to var endpoint = 'https://nodejs.org/api/'; //console.log('attempting to GET %j', endpoint); var opts = url.parse(endpoint); // create an instance of the `PacProxyAgent` class with the PAC file location var agent = new PacProxyAgent(proxy,opts); opts.agent = agent; https.get(opts, function (res) { console.log('"response" event!', res.headers); res.pipe(process.stdout); });
But it's not working, it throws the error
Chrome behavior:
I configured the PAC file in windows proxy settings
After that I am not getting any response from any sites ex: when I enter https://gmail.com/ it ends up with
any suggestions?