mswjs / interceptors

Low-level network interception library.
https://npm.im/@mswjs/interceptors
MIT License
565 stars 127 forks source link

fix(ClientRequest): support `addRequest` from custom http agents #666

Open kettanaito opened 3 weeks ago

kettanaito commented 3 weeks ago
kettanaito commented 3 weeks ago

I think the test failures are related to some HTTP requests being bypassed when they shouldn't be. Perhaps the super.addRequest() actually schedules the request to be performed. I need to look into that and make sure that's only called for passthrough requests if that's the case.

kettanaito commented 3 weeks ago

Issue

The flow is this:

  1. addRequest
  2. createSocket
  3. createConnection

If we call this.customAgent.addRequest(), it will likely tap into super.addRequest() of the http.Agent it extends, triggering the actual connection.

I'm trying to patch the http.Agent class so that any custom agents that extend it don't instantiate actual requests by tapping into super. Instead, the actual request will be instantiated in the MockHttpAgent in individual request's context.