solid-auth-client icon indicating copy to clipboard operation
solid-auth-client copied to clipboard

Should handle copying of headers when they're of type Headers

Open megoth opened this issue 7 years ago • 1 comments

options.headers might be a simple object or iniated with the Headers API. Copying an object of type Headers using spread syntax will not copy the key-values stored within the object.

As auth.fetch is a wrapper for the Fetch API, we might expect people to use the Headers API to initiate headers that are passed through the options parameter.

I have created a branch that aims to fix this, but struggle a bit with the tests, so need some help.

megoth avatar Nov 12 '18 12:11 megoth

Can we just fix it in webid-oidc.js by replacing

...(options && options.headers ? options.headers : {}),

with

...toObject(options && options.headers),

where

function toObject(headers = {}) {
  if (typeof headers.forEach !== 'function')
    return headers
  const newHeaders = {}
  headers.forEach((value, key) => {
    newHeaders[key] = value
  })
  return newHeaders
}

Then we can simply test in solid-auth-client.spec.js as a variant of https://github.com/solid/solid-auth-client/blob/v2.2.11/src/test/solid-auth-client.spec.js#L527.

RubenVerborgh avatar Nov 12 '18 13:11 RubenVerborgh