Answer the question
In order to leave comments, you need to log in
Node.JS tunneling HTTP/HTTPS/etc requests through a proxy?
I am creating a stable socket connection to a proxy server and I need to send requests to different domains and protocols (http, https, etc). Faced the problem of sending requests using the received socket after connecting to the proxy server:
var socket = net.connect(
1111, // proxy port
'xx.xx.xxx.xx' // proxy host
);
socket.on('connect', function(a) {
console.log('--- connect', socket.remoteAddress);
// connecting to https host
socket.write(
'CONNECT www.google.com:443 HTTP/1.1\r\n' +
'Proxy-Connections: keep-alive\r\n' +
'Host: www.google.com\r\n\r\n',
function() {
// send GET request and wait for response
socket.write(
'GET / HTTP/1.0\r\n' +
'User-Agent: Node.js/0.6.6\r\n' +
'Connection: keep-alive\r\n' +
'Host: www.google.com\r\n\r\n',
function(a) {
return socket;
}
);
/*
another requests to different protocols/ports...
socket.write(...)
*/
return socket;
});
});
socket.on('data', function(a) {
console.log('--- data', a.toString());
});
socket.on('drain', function() {
console.log('drain!');
});
socket.on('timeout', function() {
console.log('timeout!');
});
socket.on('close', function() {
console.log('Connection closed');
});
socket.on('end', function() {
console.log('Connection end');
});
--- connect xx.xx.xxx.xx
--- data HTTP/1.0 200 Connection established
Connection end
Connection closed
ssl3_get_record:wrong version number
ssl3_methods is disabled
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question