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

fix(ClientRequest): prevent rawHeaders from being shared across instances #694

Merged
merged 3 commits into from
Jan 2, 2025

Conversation

mikicho
Copy link
Contributor

@mikicho mikicho commented Dec 21, 2024

fixes #681

@@ -118,7 +118,7 @@ export function recordRawFetchHeaders() {
[Reflect.get(headersInit, kRawHeaders)],
newTarget
)
ensureRawHeadersSymbol(headers, Reflect.get(headersInit, kRawHeaders))
ensureRawHeadersSymbol(headers, [...Reflect.get(headersInit, kRawHeaders)])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to add a @note comment here explaining that spreading the headers creates their copy + what issue this prevents.

@@ -241,3 +241,15 @@ it('does not throw on using Headers before recording', () => {
request.headers.set('X-My-Header', '1')
expect(getRawFetchHeaders(request.headers)).toEqual([['X-My-Header', '1']])
})

it('does not use the same instance of rawHeaders', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rawHeaders inclusion in the name is probably not needed. How about

it('isolates the headers on the instance basis')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also like linking GitHub issues above the test case names so it's easier to grasp the context for bug fixes.

@kettanaito kettanaito changed the title fix(ClientRequest): clone rawHeaders array fix(ClientRequest): prevent rawHeaders from being shared across instances Jan 2, 2025
@kettanaito kettanaito merged commit a5ef7ea into main Jan 2, 2025
2 checks passed
@kettanaito kettanaito deleted the Michael/fix-clone-headers branch January 2, 2025 17:44
@kettanaito
Copy link
Member

Released: v0.37.4 🎉

This has been released in v0.37.4!

Make sure to always update to the latest version (npm i @mswjs/interceptors@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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cloned Headers modifies future clones
2 participants