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

Headers is undefined when not handling request #1120

Closed
kentcdodds opened this issue Feb 25, 2022 · 4 comments · Fixed by #1136
Closed

Headers is undefined when not handling request #1120

kentcdodds opened this issue Feb 25, 2022 · 4 comments · Fixed by #1136
Labels
bug Something isn't working scope:node Related to MSW running in Node

Comments

@kentcdodds
Copy link
Contributor

kentcdodds commented Feb 25, 2022

Environment

Name Version
msw 0.38.1
node 16
OS macOS

Request handlers

import { setupServer } from 'msw/node'

const server = setupServer()

server.listen()

Actual request

I'm not making the request, the AWS SDK is. The line that's breaking is this one though:

https://github.com/aws/aws-sdk-js/blob/6cf8513d4012e3bc07330c523cf10f45ce807ff5/lib/event_listeners.js#L412

Current behavior

When I install msw and use interception without providing any handlers, the headers object is undefined. If I add a console.log of the resp.httpResponse in the AWS SDK code, I get this:

image

Downgrading to MSW@0.36.8 resolves this issue

Expected behavior

I expect the headers to exist. I really expect the entire request to happen without any change when I don't handle the request.

@kentcdodds kentcdodds added bug Something isn't working scope:node Related to MSW running in Node labels Feb 25, 2022
@kettanaito
Copy link
Member

Hey, @kentcdodds. Thanks for reporting this!

The issue seems related to mswjs/interceptors#212. Node 12 is the latest officially supported version for MSW. We will upgrade to newer versions soon, as 12 is a rather old one at this point.

I'm curious to know what changed in 16 that headers are not present anymore. I suspect that PassThrough that we use to clone IncomingMessage now behaves differently. I'd appreciate any input and help on this from anybody interested.

@trevoro
Copy link

trevoro commented Feb 27, 2022

I think the issue is that in Node 16 the headers are on the prototype and in Node 12 they're on the instance. When a node interceptor clones a message, it only clones the object instance values and not the prototype values.

https://github.com/nodejs/node/blob/v12.x/lib/_http_incoming.js#L61
https://github.com/nodejs/node/blob/v16.x/lib/_http_incoming.js#L107-L124

@kettanaito
Copy link
Member

Yeap, @trevoro, that's the case. I like your initiative to update the supported Node.js version. That will include updating how we handle headers as well.

@github-actions
Copy link

github-actions bot commented Mar 7, 2022

🎉 This issue has been resolved in version 0.39.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

3 participants