Skip to content

Commit

Permalink
Fix for sending files with size 0 on stat (#1488)
Browse files Browse the repository at this point in the history
  • Loading branch information
Giotino committed Oct 20, 2020
1 parent 6aa86f2 commit 7acd380
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions source/core/utils/get-body-size.ts
Expand Up @@ -29,6 +29,11 @@ export default async (body: unknown, headers: ClientRequestArgs['headers']): Pro

if (body instanceof ReadStream) {
const {size} = await statAsync(body.path);

if (size === 0) {
return undefined;
}

return size;
}

Expand Down
14 changes: 14 additions & 0 deletions test/stream.ts
Expand Up @@ -443,3 +443,17 @@ if (process.versions.node.split('.')[0] <= '12') {
}));
});
}

// Test only on Linux
const testFn = process.platform === 'linux' ? test : test.skip;
testFn('it sends a body of file with size on stat = 0', withServer, async (t, server, got) => {
server.post('/', async (request, response) => {
response.end(await getStream(request));
});

const response = await got.post({
body: fs.createReadStream('/proc/cpuinfo')
});

t.truthy(response.body);
});

0 comments on commit 7acd380

Please sign in to comment.