Skip to content
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

MSW node does not intercept if I set 'X-Request-Id' #1935

Closed
4 tasks done
cythrawll opened this issue Dec 18, 2023 · 6 comments · Fixed by #2110
Closed
4 tasks done

MSW node does not intercept if I set 'X-Request-Id' #1935

cythrawll opened this issue Dec 18, 2023 · 6 comments · Fixed by #2110
Assignees
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node

Comments

@cythrawll
Copy link

cythrawll commented Dec 18, 2023

Prerequisites

Environment check

  • I'm using the latest msw version
  • I'm using Node.js version 18 or higher

Node.js version

v18.16.1

Reproduction repository

https://codesandbox.io/p/devbox/eager-kapitsa-s4cnj7

Reproduction steps

  1. create any handler.
  2. create a call that should hit the handler.
  3. see that it gets intercepted correctly.
  4. Add 'X-Request-Id' header to call with any content.
  5. See the call doesn't get intercepted.

Current behavior

Calls with X-Request-Id header do not get intercepted. This worked in msw 1.x.

https://github.com/mswjs/interceptors/blob/122a6533ce57d551dc3b59b3bb43a39026989b70/src/interceptors/ClientRequest/NodeClientRequest.ts#L193

Expected behavior

Calls with X-Request-Id should be intercepted.

We use that header to pass the request id from the browser request back to the backend for logging purposes. So we would like to intercept those requests. This header is a commonly used header for logging purposes.

@cythrawll cythrawll added bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node labels Dec 18, 2023
@kkhanhluu
Copy link

Hi @cythrawll do you still encounter this issue?

@cythrawll
Copy link
Author

cythrawll commented Mar 14, 2024

@kkhanhluu I've had to roll back my 2.0 migration because of this bug. I've not heard any movement on this issue so I assume it's still an issue? Considering it took some effort in migration and our mocks have moved so much since then, I cannot test this issue at this time unless I see movement on the issue. It looks like the code still has the same header check. Is there a concern it might have been fixed?

@kettanaito
Copy link
Member

Thanks for reporting this, @cythrawll.

The X-Request-Id header is used internally by Interceptors to dedupe nested interceptors, such as XHR implemented via http in JSDOM (XMLHttpRequestInterceptor -> ClientRequestInterceptor).

This is not a good solution. I've opened a task to replace it (mswjs/interceptors#378). AsyncLocalStorage is a great way to mitigate this for a particular XHR -> ClientRequest scenario.

@kettanaito
Copy link
Member

I've merged a workaround that would prevent Interceptors from meddling with the user-defined X-Request-Id header (mswjs/interceptors#529). Will propagate to MSW soon.

@kettanaito
Copy link
Member

Opened a fix for this in #2110.

@kettanaito
Copy link
Member

Released: v2.2.12 🎉

This has been released in v2.2.12!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants