Skip to content

Instantly share code, notes, and snippets.

@trytone
Created March 20, 2019 20:05
Show Gist options
  • Save trytone/451c359fb78435d3eca5e9c0cf5380aa to your computer and use it in GitHub Desktop.
Save trytone/451c359fb78435d3eca5e9c0cf5380aa to your computer and use it in GitHub Desktop.
Node.js MITM HTTP proxy
var http = require('http');
var httpProxy = require('http-proxy');
var body = require("body");
var proxy = httpProxy.createProxyServer({secure:false});
proxy.on('proxyReq', (proxyReq, req) => {
if (req.body) {
console.log(req.body);
proxyReq.setHeader('Content-Length', Buffer.byteLength(req.body));
proxyReq.write(req.body);
}
});
http.createServer((req, res) => {
body(req, res, {}, (err, body) => {
req.body = body;
proxy.web(req, res, {
target: 'http://targetserver.com',
secure: false,
toProxy: true,
changeOrigin: true
});
});
}).listen(80);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment