Created
February 14, 2012 00:26
-
-
Save tjanczuk/1821852 to your computer and use it in GitHub Desktop.
Proxied HTTPS request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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