-
-
Notifications
You must be signed in to change notification settings - Fork 147
feat: intercept requests on the net socket level
#741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
3a74846 to
6f76977
Compare
6f76977 to
1e3b90f
Compare
bb5e026 to
32fcd0f
Compare
5e9c2fe to
5429699
Compare
a149d32 to
8452422
Compare
e4ef073 to
2c7f4e9
Compare
net socket level
On XMLHttpRequestCurrently, we're testing XHR in JSDOM (so it's faster). That means that the global I do not encourage JSDOM or DOM-like environments, in general. We should migrate our XHR test to the real browser (we already have in-browser tests but afaik they aren't using Vitest Browser Mode; Playwright might be an overkill for our needs). For the JSDOM users, we may provide a recipe of how to enable the interceptor as a part of their environment so they have some reference. XMLHttpRequest interceptionDespite the net interceptor, some specialized client interception must still happen on the client level. That includes XHR! We should keep Important The net interceptor is intended to be used as a low-level mechanism for Node.js requests. We can and likely should keep more specialized interceptors, like XHR, both to preserve the usage-level info (e.g. |
988dfdd to
31fa254
Compare
99d10ac to
4d4f851
Compare
d3faabe to
e375e22
Compare
Discovery: Missing protocol check for HTTPS
|
fe44b85 to
6318aea
Compare
Note: Internal HTTP parser is not associated with the socketThe HTTP parsers we create for parsing out requests and responses are not associated with the underlying socket, mocked or passthrough, in any way. Those sockets create their own parsers per Node.js and keep using them for their own purposes. This is important to keep in mind when we free our own parsers. No need to nuke the
|
net.connection#707Motivation
This finally moves the request interception to the un-opinionated
netmodule level, allowing each interceptor to route socket packets through their respective parsers (HTTP, SMTP, etc).Changes
SocketInterceptorpatchesnet.connect()andnet.createConnection()to introduce a proxy socket instance to listen to outgoing packets and mock incoming packets.HttpRequestInterceptor, can now become truly client-agnostic and use the underlying socket interceptor (should probably be a singleton) to provision the interception.freeParser()internal utility.Roadmap
MockHttpSocketsomehow as it handles the suppression of connection errors and passthrough properly.socket.connect()innet.connect(). Instead, delegate that action to the user (i.e. the interceptor). Just in case they want to abort the connection before establishing it.connect? Double-check this. If so, we must emit a preemptiveconnectbut only in theHttpRequestInterceptor.HttpRequestInterceptorClientRequestInterceptorUpdate. Out of scope. New feature.XMLHttpRequestInterceptorUpdateFetchInterceptor..prependOnce()is implemented via.prepend()and if that's the case, ignore recording.prependOnce()like we do with.once().MockSocketto stop the recording after initiating a mocked response. At that point, we know we will never need to replay those recordings (they are only for passthrough). Just call something likesocket[kRecorder].free()inHttpRequestInterceptor.respondWith().secureConnectbefore writing anything #745 (comment) to verify that these changes fix the referenced issue (secureConnectbefore.write()).SocketController.constructor: finish theonEntrycallback of the recorder for passthrough requests. This fails the tests right now.SocketInterceptorwill be reused across multiple higher-level interceptors. Should it be used as a singleton? Or just constructed everywhere and rely on the existing symbol-base interceptor deduping? Any pros/cons here?