node-http-mitm-proxy
node-http-mitm-proxy copied to clipboard
New example
Description
- In some cases, the users want to inspect the request body before sending it to the real server, similar to issue 187
- With this implementation, the library can't support that. So I've forked this repo, add some changes and published a new library
- Now we can write code like this to inspect the body before sending it to the real server
proxy.onRequest(function (ctx, callbackOnRequest) {
let requestBody: Buffer[] = [];
// This event is fired at the same time as the `proxy.onRequest` event is fired
ctx.onRequestData(function (ctx, chunk, callback) {
requestBody.push(chunk);
callback(null, chunk);
});
// This event is fired after the `ctx.onRequestData` event has finished
ctx.onRequestEnd(function (ctx, callback) {
const rawBody = Buffer.concat(requestBodyBuffer);
console.log("Request body before sending it to the real server: ", rawBody);
// If the body doesn't meet your condition, just stop the process
// ctx.proxyToClientResponse.end("Stop the request");
callbackOnRequest();
});
});
Notes
- This's my first time contributing to an open-source, so please let me know if I did something wrong 👍🏻 .
- Thank you for creating the great MITM library 🚀 🚀
- I'm wondering why I can't request the review 🤔 , feel free to review this at your convenience 👍🏻
@kics223w1 Would it not make msore sense to create a minimum example in the examples folder here then linking outside?