-
-
Notifications
You must be signed in to change notification settings - Fork 127
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
Deprecate "X-Request-Id" in favor of another request deduplication algorithm #378
Comments
Hi, @ido323. Thanks for bringing this up. I agree with you, we shouldn't modify the outgoing requests. This means we should find a better way to implement the internal logic dependent on the The intention here is that in some environments, the request client can be implemented using multiple nested APIs. For example, when you construct an This library ships with both XHR and ClientRequest (http) interceptors. Moreover, the higher consumer, like MSW, is likely to use both of those interceptors at the same time. This means that whenever an XHR request happens in Node.js, it will trigger the XHR interceptor first and then the ClientRequest interceptor second (based on the invocation order of XHR -> http.ClientReuqest; this is not the library's specific behavior). When that happens, we will see the same request attempted to be handled twice, which is a mistake given that both interceptors will try to resolve the XHR request against a single To prevent this, and halt the double resolution of XHR requests in Node.js, we've added an internal interceptors/src/interceptors/ClientRequest/NodeClientRequest.ts Lines 143 to 150 in fec0789
By design, the outgoing request should never have this internal header set since the XHR request journey will always be:
Do you have a reproduction repository for me to see when this issue occurs for you, @ido323? |
@kettanaito Hello. I faced exactly the same problem. I realized that The problem is that the header You can reproduce problem in this repo. Run the following commands and open address
As a result you can see that request to
|
Thanks for the input, @avivasyuta.
Yes, this is intentional. In the older versions of Node.js, various request clients could be implemented via the I'm still unsure we can remove it completely due to the One of the things I considered was using Symbols on request instances. If an XHR request happens, the underlying |
@kettanaito Unfortunately, I have no idea how you can pass an identifier between xmlhttprequest and http instances, given that these are completely unrelated entities. It seems to me that it makes sense to use the header entirely. In modern solutions, it is not necessary. |
@avivasyuta, actually, they are not. |
@kettanaito However |
We can easily check in |
Yes. this is exactly what I mean. It should work. |
I think we can simply make such logic. |
@kettanaito Hello. It would be great if you can review my PR and make a release with bug fix. |
AsyncLocalStorage in Node.js works great for this but it's not a universal algorithm. Interceptors are meant to be environment-agnostic. The deduping of events must work the same in Node.js and in the browser. |
Since the request that hits multiple interceptors will happen in the same context by design, perhaps we can try using symbols on the request somehow to let the underlying interceptor know it should ignore it? Affecting request headers, which is a user-defined input, is not nice. |
Hi!
Thanks for your work. I appreciate the recent addition of the X-Request-Id header for each request. However, it seems to be causing a header CORS issue when the server doesn't allow it. Is there a way to make it optional or find an alternative solution without modifying the server? Your help would be greatly appreciated.
Link to the code:
interceptors/src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts
Line 173 in 94f0369
The text was updated successfully, but these errors were encountered: