Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New example #286

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

kics223w1
Copy link

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 🚀 🚀

kics223w1 and others added 7 commits April 8, 2023 18:12
* feat: update logic

* refactor: remove object after the work has done

* fix typo

* refactor: remove unnecessary changes
* refactor: update README

* refactor: update README

* refactor: update README
* refactor: update README

* refactor: update README

* refactor: update README

* refactor: update README
@kics223w1
Copy link
Author

  • I'm wondering why I can't request the review 🤔 , feel free to review this at your convenience 👍🏻

@Apollon77
Copy link
Contributor

@kics223w1 Would it not make msore sense to create a minimum example in the examples folder here then linking outside?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants