Skip to content

Commit

Permalink
Ignore the content-length while reading the request body
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Sep 1, 2023
1 parent f269ea9 commit 96efb10
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/odd-shirts-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@whatwg-node/node-fetch': patch
'@whatwg-node/fetch': patch
---

Ignore content-length while reading the request body
2 changes: 1 addition & 1 deletion packages/node-fetch/src/Body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class PonyfillBody<TJSON = any> implements Body {
if (chunks.length === 1) {
return chunks[0] as Buffer;
}
return Buffer.concat(chunks, this.contentLength || undefined);
return Buffer.concat(chunks);
});
}

Expand Down
10 changes: 9 additions & 1 deletion packages/node-fetch/tests/fetch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('Node Fetch Ponyfill', () => {
const body = await response.json();
expect(body.data).toBe('test');
});
it.only('should accept FormData bodies', async () => {
it('should accept FormData bodies', async () => {
const formdata = new PonyfillFormData();
formdata.append('test', 'test');
formdata.append(
Expand Down Expand Up @@ -138,5 +138,13 @@ describe('Node Fetch Ponyfill', () => {
const body = await response.json();
expect(body.brotli).toBe(true);
});
it('should load correctly', async () => {
const response = await fetchPonyfill(
'https://api.apis.guru/v2/specs/mashape.com/geodb/1.0.0/swagger.json',
);
expect(response.status).toBe(200);
const body = await response.json();
expect(body.swagger).toBe('2.0');
});
});
});

0 comments on commit 96efb10

Please sign in to comment.