I am trying to create a debug proxy so that I can get requests and responses when calling various APIs, but I I'm stuck where I'm trying to send data.
How can I send a part in the original law?
var httpProxy = require ('http-proxy'); Write Var 2; Write function (chuck, encoding) {/ * error: object # & lt; Object & gt; There is no way '_implicitHeader' because write2 is not a clone * / // write2 (piece, encoding); If (buffer. Isffer (chuck)) {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); My project is.
little change
function.prototype.clone = function () {Var that = this; Var temp = function temporary () {that.apply return (this, argument); }; Set (key) {object.defineProperty (temp, key, {get: function}} set that [key];} set: function (value) {that [key] = value;}}) ; } Return temporary; }; I have changed the clone animation, instead use the getters and setters to reflect any change in the cluster function properties on the clone object.
Now you can use something like write2 = res.write.clone ().
One more thing, you can replace this function with prototype assignment in a common way (pass to clone the function) which may be slightly cleaner in your design.
Comments
Post a Comment