Skip to content

Commit 7acd380

Browse files
authoredOct 20, 2020
Fix for sending files with size 0 on stat (#1488)
1 parent 6aa86f2 commit 7acd380

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
 

‎source/core/utils/get-body-size.ts

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ export default async (body: unknown, headers: ClientRequestArgs['headers']): Pro
2929

3030
if (body instanceof ReadStream) {
3131
const {size} = await statAsync(body.path);
32+
33+
if (size === 0) {
34+
return undefined;
35+
}
36+
3237
return size;
3338
}
3439

‎test/stream.ts

+14
Original file line numberDiff line numberDiff line change
@@ -443,3 +443,17 @@ if (process.versions.node.split('.')[0] <= '12') {
443443
}));
444444
});
445445
}
446+
447+
// Test only on Linux
448+
const testFn = process.platform === 'linux' ? test : test.skip;
449+
testFn('it sends a body of file with size on stat = 0', withServer, async (t, server, got) => {
450+
server.post('/', async (request, response) => {
451+
response.end(await getStream(request));
452+
});
453+
454+
const response = await got.post({
455+
body: fs.createReadStream('/proc/cpuinfo')
456+
});
457+
458+
t.truthy(response.body);
459+
});

0 commit comments

Comments
 (0)
Please sign in to comment.