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

Request.headers is shared across Requests. Is it OK? #1075

Closed
yutakahirano opened this issue Aug 18, 2020 · 5 comments
Closed

Request.headers is shared across Requests. Is it OK? #1075

yutakahirano opened this issue Aug 18, 2020 · 5 comments
Labels
compat Standard is not web compatible or proprietary feature needs standardizing topic: api

Comments

@yutakahirano
Copy link
Member

const r1 = new Request('/');
const r2 = new Request(r1);

Because r2 is created without init argument, r2's associated request's header list is r1's associated request's header list. Hence modification is shared.

r1.headers.set('x', 'y');
r2.headers.get('x') // => returns 'y'.

Is it OK? Or should we clone the header list?

This was introduced at #560 I think.

@youennf @annevk @jakearchibald

@jakearchibald
Copy link
Collaborator

Hm, it does feel like cloning is better. Sorry if I caused this.

@annevk
Copy link
Member

annevk commented Aug 18, 2020

Agreed that this should clone and that's also what browsers do (r1.headers !== r2.headers in at least Firefox and Chrome).

@annevk annevk added topic: api compat Standard is not web compatible or proprietary feature needs standardizing labels Aug 18, 2020
@annevk
Copy link
Member

annevk commented Jan 30, 2021

I looked at https://fetch.spec.whatwg.org/#dom-request and it seems that step 13 always copies the underlying header list and step 31 always creates a new Headers object. What am I missing?

@yutakahirano
Copy link
Member Author

Oh I see. I was looking at 33.1 and I thought the copy there was critical, which was wrong.

Sorry for the noise.

@annevk
Copy link
Member

annevk commented Feb 1, 2021

No problem, thanks for verifying!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compat Standard is not web compatible or proprietary feature needs standardizing topic: api
Development

No branches or pull requests

3 participants