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.
While Node v17 introduced the Fetch API from browsers, Node v18 made it non-experimental. Mitm.js's low-level implementation already hooks into the TCP connection the Fetch implementation does, but doesn't trigger request on Mitm's instance. For access to the HTTP request, Mitm.js hooked into ClientRequest. With Fetch, it'd need to hook somewhere else.
Alternatively Mitm.js could run Node.js's HTTP server/parser on the TCP connection, but we wouldn't know which connection is meant to be mocked as an HTTP connection and which as not. If we could get that info from the programmer, that'd be a breaking change. Better support Fetch with the current Mitm.js API and look into more flexibility in the future.
While Node v17 introduced the Fetch API from browsers, Node v18 made it non-experimental. Mitm.js's low-level implementation already hooks into the TCP connection the Fetch implementation does, but doesn't trigger
request
on Mitm's instance. For access to the HTTP request, Mitm.js hooked intoClientRequest
. With Fetch, it'd need to hook somewhere else.Alternatively Mitm.js could run Node.js's HTTP server/parser on the TCP connection, but we wouldn't know which connection is meant to be mocked as an HTTP connection and which as not. If we could get that info from the programmer, that'd be a breaking change. Better support Fetch with the current Mitm.js API and look into more flexibility in the future.