Created
March 20, 2019 20:05
-
-
Save trytone/451c359fb78435d3eca5e9c0cf5380aa to your computer and use it in GitHub Desktop.
Node.js MITM HTTP proxy
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'); | |
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