Yes ... it's not in my head. Please note that I am connecting to port 80 as most websites serve port 80. Change the code for your specific use case. This is in CoffeeScript.
Magazine Headers:
fs = require('fs') httpProxy = require('http-proxy') fsw = fs.createWriteStream('myfile.txt', flags: 'a', mode: 0666, encoding: 'utf8') server = httpProxy.createServer (req, res, proxy) -> req.connection.pipe(fsw)
JS Translation
Put 'localhost' and port 8080 for your proxy server. Does this work for you?
Log request body:
fs = require('fs') httpProxy = require('http-proxy') server = httpProxy.createServer (req, res, proxy) -> body = '' req.on 'data', (chunk) -> body += chunk req.on 'end', -> fs.writeFile('mybody.txt', body, 'utf8') proxy.proxyRequest(req, res, { host: require('url').parse(req.url).hostname, port: 80 }) server.listen(8080)
I checked this and can confirm that it registers the body of the POST / PUT.
Log response body:
fsw = fs.createWriteStream('myfile.txt', flags: 'a', mode: 0666, encoding: 'utf8') server = httpProxy.createServer (req, res, proxy) -> oldwrite = res.write res.write = (data, encoding, fd) -> fsw.write(data) res.write = oldwrite res.write(data, encoding, fd) res.write = oldwrite
It may not be the cleanest way, but I can confirm that it works.