@crawlee/http 4.0.0-beta.110 → 4.0.0-beta.112

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ import type { BasicCrawlerOptions, ConcurrencySystem, ConcurrencySystemOptions,
2
2
  import { BasicCrawler, ContextPipeline } from '@crawlee/basic';
3
3
  import { type LoadedRequest } from '@crawlee/core';
4
4
  import type { Awaitable, Dictionary } from '@crawlee/types';
5
- import { type CheerioRoot } from '@crawlee/utils';
5
+ import { type CheerioRoot } from '@crawlee/utils/internal';
6
6
  import type { JsonValue } from 'type-fest';
7
7
  /**
8
8
  * A higher starting concurrency and a relaxed event loop signal, since HTTP-only crawling barely touches the event
@@ -269,6 +269,8 @@ export declare class HttpCrawler<Context extends InternalHttpCrawlingContext<any
269
269
  requestList: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
270
270
  // @ts-ignore optional peer dependency or compatibility with es2022
271
271
  requestQueue: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
272
+ // @ts-ignore optional peer dependency or compatibility with es2022
273
+ requestManager: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
272
274
  // @ts-ignore optional peer dependency or compatibility with es2022
273
275
  requestHandler: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
274
276
  // @ts-ignore optional peer dependency or compatibility with es2022
@@ -1,9 +1,9 @@
1
1
  import { Readable } from 'node:stream';
2
2
  import util from 'node:util';
3
3
  import { BasicCrawler, ContextPipeline, NavigationSkippedError, remainingNavigationWindowMillis, RequestState, Router, SessionError, } from '@crawlee/basic';
4
- import { getCookiesFromResponse } from '@crawlee/core';
4
+ import { RequestThrottledError, getCookiesFromResponse } from '@crawlee/core';
5
5
  import { ResponseWithUrl } from '@crawlee/http-client';
6
- import { RETRY_CSS_SELECTORS } from '@crawlee/utils';
6
+ import { RETRY_CSS_SELECTORS } from '@crawlee/utils/internal';
7
7
  import contentTypeParser from 'content-type';
8
8
  import iconv from 'iconv-lite';
9
9
  import ow from 'ow';
@@ -262,6 +262,17 @@ export class HttpCrawler extends BasicCrawler {
262
262
  };
263
263
  }
264
264
  tryCancel();
265
+ // Before `parseResponse`, which throws for error status codes - a 429 the user opted into treating as an
266
+ // error is still a rate limit the domain should back off from.
267
+ if (crawlingContext.response.status === 429) {
268
+ const retryAfter = crawlingContext.response.headers.get('retry-after');
269
+ if (this.recordDomainRateLimit(crawlingContext.request.url, retryAfter)) {
270
+ // This is the one path that never reads the body, so cancel it to release the connection
271
+ // rather than leaving it to the garbage collector.
272
+ await crawlingContext.response.body?.cancel().catch(() => { });
273
+ throw new RequestThrottledError(`${crawlingContext.request.url} responded with 429.`);
274
+ }
275
+ }
265
276
  // Reading the body is still part of the navigation, so it draws from the same shared window: on a server
266
277
  // that streams the body slowly the request completes (headers arrive) but the body read would otherwise
267
278
  // run unbounded. `extendTimeout` from a post-navigation hook has already pushed this deadline out if asked.
@@ -1,6 +1,6 @@
1
1
  import { extname } from 'node:path';
2
2
  import { Readable } from 'node:stream';
3
- import { applySearchParams } from '@crawlee/utils';
3
+ import { applySearchParams } from '@crawlee/utils/internal';
4
4
  import contentTypeParser from 'content-type';
5
5
  import mime from 'mime-types';
6
6
  import ow, { ObjectPredicate } from 'ow';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/http",
3
- "version": "4.0.0-beta.110",
3
+ "version": "4.0.0-beta.112",
4
4
  "description": "The scalable web crawling and scraping library for JavaScript/Node.js. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.",
5
5
  "engines": {
6
6
  "node": ">=22.0.0"
@@ -49,11 +49,11 @@
49
49
  "dependencies": {
50
50
  "@apify/timeout": "^0.4.4",
51
51
  "@apify/utilities": "^2.15.5",
52
- "@crawlee/basic": "4.0.0-beta.110",
53
- "@crawlee/core": "4.0.0-beta.110",
54
- "@crawlee/http-client": "4.0.0-beta.110",
55
- "@crawlee/types": "4.0.0-beta.110",
56
- "@crawlee/utils": "4.0.0-beta.110",
52
+ "@crawlee/basic": "4.0.0-beta.112",
53
+ "@crawlee/core": "4.0.0-beta.112",
54
+ "@crawlee/http-client": "4.0.0-beta.112",
55
+ "@crawlee/types": "4.0.0-beta.112",
56
+ "@crawlee/utils": "4.0.0-beta.112",
57
57
  "@types/content-type": "^1.1.8",
58
58
  "cheerio": "^1.0.0",
59
59
  "content-type": "^1.0.5",
@@ -70,5 +70,5 @@
70
70
  }
71
71
  }
72
72
  },
73
- "gitHead": "71f42c48f431ca46b04491eca65b191691e75033"
73
+ "gitHead": "5d1e107d4dc4ffd21f1c6cc5b1a1c10b59ca2b47"
74
74
  }