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。