node-mitm icon indicating copy to clipboard operation
node-mitm copied to clipboard

Configurable delay options on the original socket

Open kamaz opened this issue 4 years ago • 1 comments

I was wondering how open are you for a PR that would open ability to configure a delay on the socket.

I was thinking something between these line:

Mitm.prototype.connect = function connect(orig, Socket, opts, done) {
    ...
    const origSocket = orig.call(this, opts, done)
    if (client.delay) {
      origSocket.pause()
      setTimeout(() => {
        origSocket.resume()
      }, client.delay)
    } 
    ...
}

Potential usage:

    mitm.on('connect', function (socket: any, _opts: any) {
      console.log('bypassing connection')
      socket.delay = 1000
      socket.bypass()
    })

kamaz avatar Sep 08 '21 14:09 kamaz

Hey, @kamaz! Thanks for the idea.

Not against supporting delays, but I'm not yet sure what exactly should be delayed. Perhaps the initial connection (client socket's connect)...

What are you trying to test there? Some timeouts on initial connection? Including DNS resolving delays?

moll avatar Aug 26 '24 05:08 moll