Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
fix(http-crawler): do not hang on POST without payload (#1546)
Szymon Marczak8c87390e0db1
diff --git a/packages/http-crawler/src/internals/http-crawler.ts b/packages/http-crawler/src/internals/http-crawler.tsindex b84d35b0f..31c4cd172 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<Context extends InternalHttpCrawlingContext<any, any, H};}- if (/PATCH|POST|PUT/.test(request.method)) requestOptions.body = request.payload;+ if (/PATCH|POST|PUT/.test(request.method)) requestOptions.body = request.payload ?? '';return requestOptions;}diff --git a/test/core/crawlers/http_crawler.test.ts b/test/core/crawlers/http_crawler.test.tsindex 39d89e451..b071d0930 100644--- a/test/core/crawlers/http_crawler.test.ts+++ b/test/core/crawlers/http_crawler.test.ts@@ -41,6 +41,11 @@ router.set('/redirectWithoutCookies', (req, res) => {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(['']);+});