Skip to content

Possible to intercept responses? #51

Description

@ianwsperber

Hi! It's unclear to me from the docs, but after intercepting a request is it possible to allow the request to resume and continue to its destination, so that we may intercept the response? I would like to intercept requests to record the request information, then record the response after. However I have not found a mechanism to accomplish this.

Ideally I would be able to write something to the effect of:

mitm.on('request', (req, res) => {
  recordRequest(req);
  
  req.on('response', recordResponse);
});

But this will just cause the request to hang, since I do not send back a response. I would like to be able to bypass the mocking here as one can with connections.

I've been reading over the source code and have begun to understand how mitm manages to intercept requests. If you are able to offer any pointers on why we cannot intercept the response today and how one could accomplish it, I would greatly appreciate it :) Ideally I would be able to create a PR to add this functionality.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions