Skip to content

Explain what the code does #12

@gajus

Description

@gajus

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

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() });
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions