moll / node-mitm

Intercept and mock outgoing Node.js network TCP connections and HTTP requests for testing. Intercepts and gives you a Net.Socket, Http.IncomingMessage and Http.ServerResponse to test and respond with. Super useful when testing code that hits remote servers.
Other
637 stars 48 forks source link

gRPC • http/2 - calls do not work with bypass #69

Open pabloalmeidas13 opened 3 years ago

pabloalmeidas13 commented 3 years ago

Good afternoon, first I found this library incredible, congratulations on the work!

I use lib to intercept various protocols (http, https, mongodb, rabbitmq, redis, etc. ..) however, when I try to intercept the gRPC calls made by lib Google PubSub it doesn't work like the other protocols, it seems to be looping.

investigating on the internet, i found that this lib uses under the engine called gRPC, and that in turn uses underneath called http2

Our use case is not for the purpose of TDD (unit tests), but I use it as a Firewall allowing or not requests.

Below is an example of my code:

` var Mitm = require("mitm"); var mitm = Mitm(); mitm.enable();

    mitm.on("connect", function(socket:any, opts:any) {
        socket.bypass();
        try{         
            if("my release rule") {
                socket.bypass();
            }
            else {
                socket.end();
            }
        }
        catch(err){
            socket.end();
        }
    });

`

Nodejs : v12.16.1

moll commented 3 years ago

Hey!

Thanks for the heads-up! Yeah, it probably indeed doesn't work with HTTP/2 yet. I should take a look how that's implemented in Node.js.

pabloalmeidas13 commented 3 years ago

Tanks @moll, i'm looking forward it 👍 🚀