Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(overrider): cleanup socket event logic
Changes the logic around socket events in the Request Overrider, which had comments that correctly denoted how confusing the code was compared to what it was trying to achieve. Previous logic monkey patched the `EventEmitter.on` method on the request to watch for an addition of a `socket` listener and then emitted related events. This was added explicitly to fix issue 79 where Nock would hang when Restify was the client. This change takes a different approach and attempts to mimic what a non- mocked request would do. `ClientRequest` always emits a `socket` event after a socket is assigned to the request https://nodejs.org/api/http.html#http_event_socket Then the socket emits connect and secureConnect events. Note that the approach would more real to life, and cleaner, if the socket itself was responsible for emitting the connect events. However, doing so while ensuring they only fire after the Requests 'socket' event requires at least two processes ticks and that breaks assumptions in our `end` method. It sill might be a nice to have in the future, but would require a larger refactor. `once` on the request is no longer aliased to `on`. Also moves yet another alias for a socket, `IncomingMessage.client`, up to where the other aliases are defined.
- Loading branch information
1 parent
7eef487
commit 8c582ab
Showing
4 changed files
with
33 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters