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

Inconsistent headers object returned after a retried request #393

Closed
cmgdragon opened this issue May 7, 2024 · 0 comments · Fixed by #436
Closed

Inconsistent headers object returned after a retried request #393

cmgdragon opened this issue May 7, 2024 · 0 comments · Fixed by #436

Comments

@cmgdragon
Copy link

cmgdragon commented May 7, 2024

Environment

ofetch 1.3.4
node 20.12.2

Reproduction

https://stackblitz.com/edit/vitejs-vite-53ww8b?file=main.js

Open the devtools console and click the POST REQUEST button to see the issue

You can see how the headers are being turned into a Headers object no matter the original input, making the headers not accesible anymore when the request loops back

Describe the bug

coming from nuxt/nuxt#27042

$fetch is transforming the headers object into a Headers class if there's a body and the method is other than GET; so if headers are being added in the onRequest interceptor using normal object property accessors instead of the Headers constructor (as shown in the useFetch documentation at the moment I'm writing this issue), when the request is retried and loops back, these are being added as extra properties of the Headers object and ignored later

The expected behavior would be that the headers object was consistent across retried requests, and even across all interceptors

I think the headers object should either be normalized or at least be clear that the Headers constructor is required for modifying the request inside interceptors

Additional context

I came across this issue when I tried to refresh a JWT using the retry option along with the onResponseError interceptor: nuxt/nuxt#26991

I also tried to fix it in this commit, normalizing the headers before the retry and after the onRequest: cmgdragon@8954d8c, though this solution isn't taking into consideration any other interceptor but onRequest for modifying the headers

Logs

No response

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 a pull request may close this issue.

1 participant