0.4.0 • Published 1 year ago

custom-node-http-mitm-proxy v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Description

  • Special thanks to Joeferner for creating the great node-http-mitm-proxy library
  • This rewrite library allows you can get the full request body before the onRequest event is triggered
  • I.e. If the request body doesn't meet your condition, you can prevent it to proceed to the real server.
  • If you want to see what I have changed please check out this pull request

Install

NPM version npm.io

npm i custom-node-http-mitm-proxy

Example

proxy.onRequest(function (ctx, callbackOnRequest) {
  let requestBody: Buffer[] = [];

  ctx.onRequestData(function (ctx, chunk, callback) {
    requestBody.push(chunk);
    callback(null, chunk);
  });

  ctx.onRequestEnd(function (ctx, callback) {
    const rawBody = Buffer.concat(requestBodyBuffer);

    console.log("Request body before event onRequest has triggered: ", rawBody);

    // If the body doesn't meet your condition, just stop the process
    // ctx.proxyToClientResponse.end("Stop the request");

    callbackOnRequest();
  });
});