Skip to content

Instantly share code, notes, and snippets.

@tjanczuk
Created February 14, 2012 00:26
Show Gist options
  • Save tjanczuk/1821852 to your computer and use it in GitHub Desktop.
Save tjanczuk/1821852 to your computer and use it in GitHub Desktop.
Proxied HTTPS request
var http = require('http')
, https = require('https')
res.writeHead(200);
console.log(Object.getOwnPropertyNames(http));
console.log(http)
http.request({ // establishing a tunnel
host: 'itgproxy',
port: 80,
method: 'CONNECT',
path: 'github.com:443'
}).on('connect', function(pres, socket, head) {
if (pres.statusCode !== 200)
res.end('Proxy response status code: ' + pres.statusCode);
else
https.get({
host: 'github.com',
socket: socket, // using a tunnel
agent: false // cannot use a default agent
}, function (bres) {
bres.pipe(res);
}).on('error', function (err) {
res.end('Error talking to backend: ' + err);
});
}).on('error', function (err) {
res.end('Error talking to proxy: ' + err);
}).end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment