Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for sending files with size 0 on stat #1488

Merged
merged 2 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions source/core/utils/get-body-size.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
});