service-workers
service-workers copied to clipboard
cloning a response copies headers by reference
What I expect:
// given a response:
const responseA = new Response('hello', { status: 200, headers: { Foo: 'Bar' } })
// when you clone it:
const responseB = new Response(responseA.body, responseA)
// and change the original:
responseA.headers.set('Foo', 'Baz')
// then the clone shouldn't change:
responseB.headers.get('Foo') // 'Bar'
What happens with service-worker-mock:
// given a response:
const responseA = new Response('hello', { status: 200, headers: { Foo: 'Bar' } })
// when you clone it:
const responseB = new Response(responseA.body, responseA)
// and change the original:
responseA.headers.set('Foo', 'Baz')
// then the clone changes
responseB.headers.get('Foo') // 'Baz'
The same thing happens with Request
.
I believe the solution is to change
if (options.headers instanceof Headers) {
this.headers = options.headers;
to
if (options.headers instanceof Headers) {
this.headers = new Headers(options.headers);