我正在尝试构建一个调试代理,以便在调用各种 API 时可以看到请求和响应,但是我被困在尝试将数据发送到原始方法的地方。
我怎样才能将块发送到原始方法?
var httpProxy = require('http-proxy');
var write2;
function write (chunk, encoding) {
/*
error: Object #<Object> has no method '_implicitHeader'
because write2 is not a clone.
*/
//write2(chunk, encoding);
if (Buffer.isBuffer(chunk)) {
console.log(chunk.toString(encoding));
}
}
var server = httpProxy.createServer(function (req, res, proxy) {
// copy .write
write2 = res.write;
// monkey-patch .write
res.write = write;
proxy.proxyRequest(req, res, {
host: req.headers.host,
port: 80
});
});
server.listen(8000);
我的项目在这里。