diff --git a/packages/http-crawler/src/internals/http-crawler.ts b/packages/http-crawler/src/internals/http-crawler.ts index b84d35b0fa59..31c4cd1728a1 100644 --- a/packages/http-crawler/src/internals/http-crawler.ts +++ b/packages/http-crawler/src/internals/http-crawler.ts @@ -641,7 +641,7 @@ export class HttpCrawler { res.end(); }); +router.set('/echo', (req, res) => { + res.setHeader('content-type', 'text/html'); + req.pipe(res); +}); + let server: http.Server; let url: string; @@ -231,3 +236,23 @@ test('no empty cookie header', async () => { expect(results).toStrictEqual([]); }); + +test('POST with undefined (empty) payload', async () => { + const results: string[] = []; + + const crawler = new HttpCrawler({ + handlePageFunction: async ({ body }) => { + results.push(body.toString()); + }, + }); + + await crawler.run([ + { + url: `${url}/echo`, + payload: undefined, + method: 'POST', + }, + ]); + + expect(results).toStrictEqual(['']); +});