solid-client-authn-js
solid-client-authn-js copied to clipboard
Unable to pass custom Headers
Search terms you've used
headers, fetch init
Impacted package
Which packages do you think might be impacted by the bug ?
- [ ] solid-client-authn-browser
- [x] solid-client-authn-node
- [ ] solid-client-authn-core
- [ ] oidc-client-ext
- [ ] Other (please specify): ...
Bug description
This library seems assume that the headers field within the init object of a fetch always uses the Record<string, string>
form, while this can also be a string[][]
or Headers
.
Within Comunica, we're consistently passing around Headers
objects. But when it reaches this auth library, the headers become mangled, which causes several issues (such as being unable to set the content type on PUT/PATCH requests).
Related to #176, #96
To Reproduce
session.fetch('...', { headers: new Headers({ 'Content-Type': 'text/turtle' }) })
Expected result
Headers are delegated properly
Actual result
Headers are ignored
Environment
Please run
npx envinfo --system --npmPackages --binaries --npmGlobalPackages --browsers
in your project folder and paste the output here:
System:
OS: macOS 10.15.4
CPU: (8) x64 Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
Memory: 23.36 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 16.2.0 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 7.13.0 - /usr/local/bin/npm
Browsers:
Chrome: 94.0.4606.61
Firefox: 91.0.2
Safari: 13.1
npmGlobalPackages:
@comunica/actor-init-sparql-file: 1.14.0
@ldflex/comunica: 3.4.2
chrome-headless-render-pdf: 1.9.0
clinic: 8.0.1
componentsjs-generator: 2.6.0
generator-comunica: 1.0.0
http-server: 0.12.3
ldbc-snb-enhancer: 1.0.2
n: 6.5.1
npm-cli-adduser: 1.1.4
npm: 7.13.0
rdf-dataset-fragmenter: 1.2.0
rdf-dereference: 1.5.0
renovate: 23.20.2
verdaccio: 3.11.4
why-is-node-running: 2.2.0
yo: 3.1.1
Additional information
Places like here may need another way of merging Headers
instead of using destructuring.
Thanks for reporting this ! Indeed, I've been unlucky with headers in this library, this looks like a regression. I'll fix this very soon.
Can you give a try to the fix in https://github.com/inrupt/solid-client-authn-js/pull/1716 (by installing @inrupt/solid-client-authn-browser@fixmangled-headers
) ? (or @inrupt/solid-client-authn-node@fixmangled-headers
, depending on your use case)
@NSeydoux The new version fixes all problems on my end, thanks!
Excellent ! I'll cut a patch release and close the issue when it ships. Thanks for following up !
I just encountered this issue in SCAB (so browser, not Node) version 1.11.7. I didn't open a new issue since this one was still open. Might this have regressed again?
Good question (he said, with a bit of a delay), I'll double-check.
Yep, I can reproduce. I'll see why this has regressed (again!)
What I'm seeing is that the following results in the headers being misssing:
fetch(resource, { headers: new Headers({ Accept: "text/turtle" }) })
while this passes the headers through successfully:
fetch(resource, { headers: { Accept: "text/turtle" } })
Do you observe anything similar?
@NSeydoux Sorry, I'm not sure where I encountered this anymore, but I think that was indeed the cause (and my workaround was using the plain object).