Wrong Content-Type when passing Headers object to fetch
Search terms you've used
Impacted package
Which packages do you think might be impacted by the bug ?
- [x] solid-client-authn-browser
- [ ] solid-client-authn-node
- [ ] solid-client-authn-core
- [ ] oidc-client-ext
- [ ] Other (please specify): ...
Bug description
When passing a Headers object to fetch from @inrupt/solid-client-authn-browser the request defaults to Content-type: text/plain instead of the type specified by the object. Passing the header directly works.
To Reproduce
The following snippet illustrates the problem. The commented out part produces a Content-Type: text/plain header while setting the header property of fetch directly works as intended.
import { fetch, getDefaultSession } from "@inrupt/solid-client-authn-browser";
...
fetch(
getDefaultSession().info.webId!.replace("profile/card#me", "test3.ttl"),
{
method: "PUT",
// works!
headers: {
"Content-Type": "text/turtle",
},
// produces "Content-Type: text/plain"
// headers: new Headers({
// "Content-Type": "text/turtle",
// }),
body: `<ex:s> <ex:p> <ex:o1>.`,
}
);
Expected result
I expect that when I set Headers({"Content-Type": "text/turtle"}) to the header property of fetch that the request will have a Content-Type: text/turtleheader.
Actual result
Instead, I get a Content-Type: text/plain header.
Environment
Please run
npx envinfo --system --npmPackages --binaries --npmGlobalPackages --browsers
in your project folder and paste the output here:
$ npx envinfo --system --npmPackages --binaries --npmGlobalPackages --browsers
System:
OS: Linux 5.15 Ubuntu 22.04 LTS 22.04 LTS (Jammy Jellyfish)
CPU: (16) x64 AMD Ryzen 7 5800X 8-Core Processor
Memory: 22.96 GB / 31.26 GB
Container: Yes
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node
Yarn: 1.22.18 - ~/.yarn/bin/yarn
npm: 8.5.5 - ~/.nvm/versions/node/v16.15.0/bin/npm
Browsers:
Chrome: 102.0.5005.61
npmPackages:
@comunica/query-sparql: ^2.2.1 => 2.2.1
@comunica/query-sparql-solid: ^2.0.1 => 2.0.1
@inrupt/solid-client: ^1.23.1 => 1.23.1
@inrupt/solid-client-authn-browser: ^1.11.9 => 1.11.9
@inrupt/vocab-common-rdf: ^1.0.5 => 1.0.5
@types/react: ^18.0.10 => 18.0.10
@types/react-dom: ^18.0.5 => 18.0.5
buffer: ^6.0.3 => 6.0.3
html-webpack-plugin: ^5.5.0 => 5.5.0
n3: ^1.16.2 => 1.16.2
process: ^0.11.10 => 0.11.10
react: ^18.1.0 => 18.1.0
react-dom: ^18.1.0 => 18.1.0
stream-browserify: ^3.0.0 => 3.0.0
ts-loader: ^9.3.0 => 9.3.0
typescript: ^4.7.2 => 4.7.2
util: ^0.12.4 => 0.12.4
webpack: ^5.72.1 => 5.72.1
webpack-cli: ^4.9.2 => 4.9.2
webpack-dev-server: ^4.9.0 => 4.9.0
npmGlobalPackages:
@comunica/query-sparql: 2.2.1
corepack: 0.10.0
expo-cli: 5.3.1
npm: 8.5.5
Additional information
Related to the original issue opened on Comunica solid: https://github.com/comunica/comunica-feature-solid/issues/30
Other relevant information is the fact that this seems to work fine on solid-client-authn-node. So only solid-client-authn-browser seems to be affected.
I'm sorry for the delayed response. That's a known issue that I'm planning on sorting out soon.
@remodietlicher / @rubensworks — I vaguely remember us changing something here latest year, would you be able to retest?
A bit late to the party, but this is fixed. I can't reproduce with the latest version of @inrupt/solid-client-authn-browser, so 2.0.0 is patched for sure, and I couldn't reproduce in 1.15.0 either, so it has been fixed prior to that. I should have kept a closer eye on this issue, sorry about that. There is a non-regression test for this now.