Comments (7)
I can confirm that this is only an issue with undici fetch (globalThis.fetch
)
from ofetch.
Actually, it is only an issue with undici fetch in ohmyfetch context, here's a snippet to test it out :
import http from "node:http";
import { $fetch } from "ohmyfetch/node";
const server = http.createServer((req, res) => {
console.log(req.headers);
res.end();
});
server.listen(8000);
for(const fetchImpl of [fetch, $fetch]) {
await fetchImpl("http://localhost:8000", {
body: { lo: "dibidon" },
headers: {
"content-type": "application/json"
},
method: "POST"
});
}
globalThis.fetch:
{
host: 'localhost:8000',
connection: 'keep-alive',
'content-type': 'application/json',
accept: '*/*',
'accept-language': '*',
'sec-fetch-mode': 'cors',
'user-agent': 'undici',
'accept-encoding': 'gzip, deflate',
'content-length': '0'
}
ohmyfetch:
{
host: 'localhost:8000',
connection: 'keep-alive',
'content-type': 'application/json, text/plain;charset=UTF-8',
accept: 'application/json',
'accept-language': '*',
'sec-fetch-mode': 'cors',
'user-agent': 'undici',
'accept-encoding': 'gzip, deflate',
'content-length': '16'
}
I tried on node 16 and I had no issue with node-fetch.
So, it's an issue with ohmyfetch's implementation of undici fetching. It doesn't happen with unjs/node-fetch-native
alone.
I also realized it doesn't happen if you omit the body.
from ofetch.
Let me close this issue because ohfetch does no longer support undici as of v1.0.0 and there is a workaround for the issue like using other fetch implementation.
from ofetch.
@ian4uia You have made a typo, headers are case sensitive, you can overwrite content-type
with lowercase instead of capitalised Content-Type
from ofetch.
You have made a typo, headers are case sensitive, you can overwrite
content-type
with lowercase instead of capitalisedContent-Type
it's not a typo, it's supposed to work too, overwriting using content-type
does not work better
return $fetch("https://whatever", {
body: {},
headers: {
"content-type": "application/json"
},
method: "POST"
});
Result:
Content-Type: application/json, text/plain;charset=UTF-8
I'm thinking that this is potentially an undici issue
from ofetch.
Could that it's always adding the text/plain;charset=UTF-8
on any content-type which would be not very helpful.
But what I saw in fetch.js #L121 if you wanted to overwrite it you needs to use content-type
instead of Content-Type
from ofetch.
I'm pretty sure that works for ohmyfetch, but it's probably an issue with the underlying fetch libraries used (for my case, it's using undici.fetch)
from ofetch.
Related Issues (20)
- Failed to upload Mega-sized base64 image HOT 1
- Go-like syntax to handle errors HOT 6
- error.statusText & error.statusMessage are undefined after Nuxt build but are set in dev
- deprecate `params` alias for `query` HOT 1
- the HTTP(S) Agent invalid HOT 7
- Can access to typed data in interceptors HOT 2
- Set cookies HOT 11
- error on Response.blob()
- Multipart image upload not working with fetch but with RapidAPI HOT 4
- Missing types in node export HOT 1
- `body` vs `params` option HOT 1
- Inconsistent headers object returned after a retried request
- TS2305: Module 'ofetch' has no exported member FetchOptions HOT 1
- Errors in Interceptors are silently handled
- How to handle errors body HOT 1
- GraphQL Support HOT 2
- Body in options object in $fetch method from NUXT3 not available in request to server HOT 1
- When using $fetch.raw, clone() cannot be used. HOT 2
- unexpected behavior from `ofetch.raw` and `onResponse` HOT 1
- Add support of TS type annotations on `ofetch.create` HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ofetch.