Closed arb closed 9 years ago
Hey,
The thing with agents is that they re-use a single TCP connection for multiple requests. Mitm doesn't necessarily prevent that, but tests should ideally be independent of each other. Re-using connections would cause them to be coupled.
Mitm stubs the global HTTP agent's functions merely because they had a reference to Net.connect
. I'd think other libs should work as-is as long as they don't store references to Net.connect
though. If they do, Mitm's intercept code won't be called. Have you looked into Wreck? Does it do so?
Relevant lines in Mitm.js source: https://github.com/moll/node-mitm/blob/master/index.js#L36
Any new intel, @arb?
No new info. When I told Wreck to use the default global HTTP agent, it started to work. When I left it use it's own, it did not.
Would you mind giving it another try? I added two sets of tests for use with Http.Agent
and Https.Agent
and both seem to work... I briefly checked Wreck's use of agent (https://github.com/hapijs/wreck/blob/master/lib/index.js) and it seems to be in line with what Mitm's unit tests check.
Hey again. I'll close this issue for now as there's not much I can do without your feedback. Whenever you're back, we can open it again. ;-)
It doesn't seem like mitm will catch and intercept requests if they are made using a custom Http Agent. Is that the case or am I overlooking something?
In this example "on request" is never called and I know
Wreck
by default doesn't use the global Http Agent.UPDATE Confirmed, yes currently
Mitm
can only intercept when the request library uses the global Http agent and Wreck does not by default.