0
我正在尝试构建一个调试代理,以便在调用各种API时可以看到请求和响应,但是我坚持要将数据发送到original method。在这种情况下,方法克隆会起作用吗?
我怎样才能发送块到原来的方法?
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);
我的项目是here。