Can someone with understanding of https and streams explain me whats going on here?
|
server.addListener('upgrade', function(req, socket, upgradeHead) { |
|
var proxy = net.createConnection(that.options.mitm_port, 'localhost'); |
|
|
|
proxy.on('connect', function() { |
|
socket.write( "HTTP/1.0 200 Connection established\r\nProxy-agent: Netscape-Proxy/1.1\r\n\r\n"); |
|
}); |
|
|
|
// connect pipes |
|
proxy.on( 'data', function(d) { socket.write(d) }); |
|
socket.on('data', function(d) { try { proxy.write(d) } catch(err) {}}); |
|
|
|
proxy.on( 'end', function() { socket.end() }); |
|
socket.on('end', function() { proxy.end() }); |
|
|
|
proxy.on( 'close',function() { socket.end() }); |
|
socket.on('close',function() { proxy.end() }); |
|
|
|
proxy.on( 'error',function() { socket.end() }); |
|
socket.on('error',function() { proxy.end() }); |
|
}); |
Can someone with understanding of https and streams explain me whats going on here?
node-mitm-proxy/proxy.js
Lines 140 to 159 in 864c252