In linux where "everything is a file" some files have no size when calling stat (eg. /proc/cpuinfo).
In this case Got set content-length to 0, when it should use a chunked transfer encoding.
Got set content-length to 0.
Got uses a chunked transfer encoding.
const {createReadStream} = require('fs');
const got = require('got');
const stream = createReadStream('/proc/cpuinfo');
(async () => {
const response = got('https://httpbin.org/post', {method: 'POST', body: stream});
const json = await response.json();
console.log(json)
})();
It's working properly on 9.6.0 but it's failing on 10.0.0
Works on [email protected] but doesn't on [email protected].
I think the fix is quite simple: if it's a stream go with chunked, no content-length even if we know it.
I think the fix is quite simple: if it's a stream go with chunked, no content-length even if we know it.
Ok, it's not that easy because the upload progress feature is gonna break, but at least we can go with:
if stat.size == 0
we don't know the size
else
stat.size
Ok, it's not that easy because the upload progress feature is gonna break, but at least we can go with:
That's not the right solution. The alpha version has the same getBodySize implementation and it works there.
That's not the right solution. The alpha version has the same
getBodySizeimplementation and it works there.
I'm sorry but currently I've no time to investigate this, but I can say this: if stat returned 0 and Got used that value on content-length there's no way it was working fine, except in the case of a Got bug that wasn't setting the content-length properly.
No problem, I'll look into this ASAP.