Skip to content

cloning a response copies headers by reference #142

@jamesarosen

Description

@jamesarosen

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);

in Request and Response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions