-
-
Notifications
You must be signed in to change notification settings - Fork 131
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): preserve headers type when recording raw headers #660
fix(ClientRequest): preserve headers type when recording raw headers #660
Conversation
I think the
I was able to "fix" it locally by wrapping the right hand side of the assignment in
new Headers() after finding this PR.
|
You are absolutely right...i missed this because the way to trigger it is a bit weird. Pushed the fix now. |
Awesome! Thank you! |
@@ -126,6 +126,28 @@ it('records raw headers (Reqest / Request as init)', () => { | |||
expect(getRawFetchHeaders(request.headers)).toEqual([['X-My-Header', '1']]) | |||
}) | |||
|
|||
it("doesn't change the init headers instanceof (Request / Request as init)", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe let's rephrase it to "preserves the original headers instance"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well it's not technically the same header instance...however if you think it's important we could rework this whole thing by pushing looping over the raw headers and set the on the original instance
Thanks for opening this, @paoloricciuti. I believe those 3 interceptors/src/interceptors/ClientRequest/utils/recordRawHeaders.ts Lines 219 to 230 in 2067cb0
interceptors/src/interceptors/ClientRequest/utils/recordRawHeaders.ts Lines 253 to 258 in 2067cb0
I've removed the if checks, and the tests are still passing. Let me test these changes in MSW as well, as it may have unique use cases we are not considering here. |
@@ -225,8 +188,8 @@ export function recordRawFetchHeaders() { | |||
inferredRawHeaders.push(...inferRawHeaders(args[1].headers)) | |||
} | |||
|
|||
if (inferRawHeaders.length > 0) { | |||
defineRawHeadersSymbol(request.headers, inferredRawHeaders) | |||
if (inferredRawHeaders.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a typo ✅
if (inferRawHeaders.length > 0) { | ||
defineRawHeadersSymbol(request.headers, inferredRawHeaders) | ||
if (inferredRawHeaders.length > 0) { | ||
ensureRawHeadersSymbol(request.headers, inferredRawHeaders) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I'm using ensure
to prevent the raw headers symbol from being re-defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh i don't remember changing this line...weird.
Headers
as Headers
instead of string[]
Both interceptors and MSW test suites have passed with these changes. Let's get this out. |
@paoloricciuti, welcome to contributors! 🎉 |
Released: v0.36.5 🎉This has been released in v0.36.5! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |
Closes #651
Basically when defining the header property on the original
init
request or the original init headers we were assigning the value ofkRawHeaders
but that's just a string array. So if thatRequest
is then used again trying to read theheaders
withreq.headers.get
it will fail since there's noget
method in the array of strings.Also i've noticed
which is a classic TS mystake: you were checking if that function had more than one argument but that's always true so i switched to what i think you actually wanted to check.
I've added a couple of test to check this that fails before this PR.