@crawlee/http 4.0.0-beta.11 → 4.0.0-beta.111

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.
@@ -1,71 +1,81 @@
1
- import type { IncomingMessage } from 'node:http';
2
- import type { Readable } from 'node:stream';
3
- import type { BasicCrawlerOptions, CrawlingContext, ErrorHandler, GetUserDataFromRequest, ProxyConfiguration, Request, RequestHandler, RequireContextPipeline, RouterRoutes, Session } from '@crawlee/basic';
4
- import { BasicCrawler, Configuration, ContextPipeline } from '@crawlee/basic';
5
- import type { HttpResponse, LoadedRequest } from '@crawlee/core';
1
+ import type { BasicCrawlerOptions, ConcurrencySystem, ConcurrencySystemOptions, CrawlingContext, ErrorHandler, GetUserDataFromRequest, Request as CrawleeRequest, RequestHandler, RequireContextPipeline, RouterHandler, RouterRoutes, RouteSchemas, RoutesFromSchemas } from '@crawlee/basic';
2
+ import { BasicCrawler, ContextPipeline } from '@crawlee/basic';
3
+ import { type LoadedRequest } from '@crawlee/core';
6
4
  import type { Awaitable, Dictionary } from '@crawlee/types';
7
- import { type CheerioRoot } from '@crawlee/utils';
8
- import type { RequestLike, ResponseLike } from 'content-type';
9
- // @ts-ignore optional peer dependency or compatibility with es2022
10
- import type { Method, OptionsInit } from 'got-scraping';
5
+ import { type CheerioRoot } from '@crawlee/utils/internal';
11
6
  import type { JsonValue } from 'type-fest';
12
7
  /**
13
- * TODO exists for BC within HttpCrawler - replace completely with StreamingHttpResponse in 4.0
14
- * @internal
8
+ * A higher starting concurrency and a relaxed event loop signal, since HTTP-only crawling barely touches the event
9
+ * loop. {@link HttpCrawler} folds these into the {@link ConcurrencySystem} it builds by default.
10
+ *
11
+ * A {@link BasicCrawlerOptions.concurrencySystem|`concurrencySystem`} you supply yourself replaces that default
12
+ * wholesale, tuning included, so spread these options in if you want to keep it:
13
+ *
14
+ * ```typescript
15
+ * new ConcurrencySystem({ ...HTTP_OPTIMIZED_CONCURRENCY_SYSTEM_OPTIONS, maxConcurrency: 50 });
16
+ * ```
15
17
  */
16
- export type PlainResponse = Omit<HttpResponse, 'body'> & IncomingMessage & {
17
- body?: unknown;
18
- };
18
+ export declare const HTTP_OPTIMIZED_CONCURRENCY_SYSTEM_OPTIONS: ConcurrencySystemOptions;
19
19
  export type HttpErrorHandler<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
20
- JSONData extends JsonValue = any> = ErrorHandler<HttpCrawlingContext<UserData, JSONData>>;
21
- export interface HttpCrawlerOptions<Context extends InternalHttpCrawlingContext = InternalHttpCrawlingContext, ExtendedContext extends Context = Context> extends BasicCrawlerOptions<Context, ExtendedContext> {
20
+ JSONData extends JsonValue = any, // with default to Dictionary we cant use a typed router in untyped crawler
21
+ ContextExtension = Dictionary<never>> = ErrorHandler<CrawlingContext, HttpCrawlingContext<UserData, JSONData> & ContextExtension>;
22
+ export interface HttpCrawlerOptions<Context extends InternalHttpCrawlingContext = InternalHttpCrawlingContext, ContextExtension = Dictionary<never>, ExtendedContext extends Context = Context & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<Context['request']>>> extends BasicCrawlerOptions<Context, ContextExtension, ExtendedContext, Routes> {
22
23
  /**
23
- * Timeout in which the HTTP request to the resource needs to finish, given in seconds.
24
+ * Timeout for the whole navigation phase, given in seconds. A single window shared by the
25
+ * `preNavigationHooks`, the navigation (the HTTP request to the resource), and the `postNavigationHooks` -
26
+ * so a slow hook eats into the same budget the navigation uses. Separate from the
27
+ * {@link BasicCrawlerOptions.requestHandlerTimeoutSecs|`requestHandlerTimeoutSecs`}, which times only the
28
+ * request handler.
24
29
  */
25
30
  navigationTimeoutSecs?: number;
26
31
  /**
27
32
  * If set to true, SSL certificate errors will be ignored.
28
33
  */
29
34
  ignoreSslErrors?: boolean;
30
- /**
31
- * If set, this crawler will be configured for all connections to use
32
- * [Apify Proxy](https://console.apify.com/proxy) or your own Proxy URLs provided and rotated according to the configuration.
33
- * For more information, see the [documentation](https://docs.apify.com/proxy).
34
- */
35
- proxyConfiguration?: ProxyConfiguration;
36
35
  /**
37
36
  * Async functions that are sequentially evaluated before the navigation. Good for setting additional cookies
38
- * or browser properties before navigation. The function accepts two parameters, `crawlingContext` and `gotOptions`,
39
- * which are passed to the `requestAsBrowser()` function the crawler calls to navigate.
37
+ * or browser properties before navigation. The function accepts one parameter `crawlingContext`,
38
+ * which is passed to the `requestAsBrowser()` function the crawler calls to navigate.
39
+ *
40
+ * A hook may optionally return a partial object whose properties are merged into the crawling context,
41
+ * allowing the hook to override context members for subsequent hooks and pipeline stages.
42
+ *
43
+ * The context is built up in the following order: base context (`request`, `session`, helpers, ...) ->
44
+ * `extendContext` -> `preNavigationHooks` -> navigation -> `postNavigationHooks` -> `requestHandler`.
45
+ * This means the members added by `extendContext` are already available here, but navigation-dependent
46
+ * members (e.g. `response`, `body`, `$`) are not.
40
47
  * Example:
41
48
  * ```
42
49
  * preNavigationHooks: [
43
- * async (crawlingContext, gotOptions) => {
50
+ * async (crawlingContext) => {
44
51
  * // ...
45
52
  * },
46
53
  * ]
47
54
  * ```
48
- *
49
- * Modyfing `pageOptions` is supported only in Playwright incognito.
50
- * See {@link PrePageCreateHook}
51
55
  */
52
- preNavigationHooks?: InternalHttpHook<CrawlingContext>[];
56
+ preNavigationHooks?: InternalHttpHook<CrawlingContext<any>, ContextExtension>[];
53
57
  /**
54
58
  * Async functions that are sequentially evaluated after the navigation. Good for checking if the navigation was successful.
55
59
  * The function accepts `crawlingContext` as the only parameter.
60
+ *
61
+ * A hook may optionally return a partial object whose properties are merged into the crawling context,
62
+ * which is useful for overriding the `response` after solving a challenge or re-fetching the resource.
56
63
  * Example:
57
64
  * ```
58
65
  * postNavigationHooks: [
59
66
  * async (crawlingContext) => {
60
- * // ...
67
+ * if (await needsRevalidation(crawlingContext)) {
68
+ * return { response: await refetch(crawlingContext.request) };
69
+ * }
61
70
  * },
62
71
  * ]
63
72
  * ```
64
73
  */
65
- postNavigationHooks?: ((crawlingContext: CrawlingContextWithReponse) => Awaitable<void>)[];
74
+ postNavigationHooks?: ((crawlingContext: CrawlingContextWithResponse & ContextExtension) => Awaitable<void | Partial<CrawlingContextWithResponse>>)[];
66
75
  /**
67
76
  * An array of [MIME types](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types)
68
- * you want the crawler to load and process. By default, only `text/html` and `application/xhtml+xml` MIME types are supported.
77
+ * you want the crawler to load and process. By default, only `text/html`, `application/xhtml+xml`, `text/xml`, `application/xml`,
78
+ * and `application/json` MIME types are supported.
69
79
  */
70
80
  additionalMimeTypes?: string[];
71
81
  /**
@@ -91,44 +101,28 @@ export interface HttpCrawlerOptions<Context extends InternalHttpCrawlingContext
91
101
  */
92
102
  forceResponseEncoding?: string;
93
103
  /**
94
- * Automatically saves cookies to Session. Works only if Session Pool is used.
104
+ * Automatically saves cookies to Session. Enabled by default.
95
105
  *
96
106
  * It parses cookie from response "set-cookie" header saves or updates cookies for session and once the session is used for next request.
97
107
  * It passes the "Cookie" header to the request with the session cookies.
98
108
  */
99
- persistCookiesPerSession?: boolean;
100
- /**
101
- * An array of HTTP response [Status Codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) to be excluded from error consideration.
102
- * By default, status codes >= 500 trigger errors.
103
- */
104
- ignoreHttpErrorStatusCodes?: number[];
105
- /**
106
- * An array of additional HTTP response [Status Codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) to be treated as errors.
107
- * By default, status codes >= 500 trigger errors.
108
- */
109
- additionalHttpErrorStatusCodes?: number[];
109
+ saveResponseCookies?: boolean;
110
110
  }
111
- /**
112
- * @internal
113
- */
114
- export type InternalHttpHook<Context> = (crawlingContext: Context, gotOptions: OptionsInit) => Awaitable<void>;
111
+ export type InternalHttpHook<Context, ContextExtension = {}> = (crawlingContext: Context & ContextExtension) => Awaitable<void | Partial<Context>>;
115
112
  export type HttpHook<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
116
113
  JSONData extends JsonValue = any> = InternalHttpHook<HttpCrawlingContext<UserData, JSONData>>;
117
- interface CrawlingContextWithReponse<UserData extends Dictionary = any> extends CrawlingContext<UserData> {
114
+ interface CrawlingContextWithResponse<UserData extends Dictionary = any> extends CrawlingContext<UserData> {
118
115
  /**
119
116
  * The request object that was successfully loaded and navigated to, including the {@link Request.loadedUrl|`loadedUrl`} property.
120
117
  */
121
- request: LoadedRequest<Request<UserData>>;
118
+ request: LoadedRequest<CrawleeRequest<UserData>>;
122
119
  /**
123
120
  * The HTTP response object containing status code, headers, and other response metadata.
124
121
  */
125
- response: PlainResponse;
122
+ response: Response;
126
123
  }
127
- /**
128
- * @internal
129
- */
130
124
  export interface InternalHttpCrawlingContext<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
131
- JSONData extends JsonValue = any> extends CrawlingContextWithReponse<UserData> {
125
+ JSONData extends JsonValue = any> extends CrawlingContextWithResponse<UserData> {
132
126
  /**
133
127
  * The request body of the web page.
134
128
  * The type depends on the `Content-Type` header of the web page:
@@ -189,38 +183,40 @@ JSONData extends JsonValue = any> = RequestHandler<HttpCrawlingContext<UserData,
189
183
  *
190
184
  * This crawler downloads each URL using a plain HTTP request and doesn't do any HTML parsing.
191
185
  *
192
- * The source URLs are represented using {@link Request} objects that are fed from
193
- * {@link RequestList} or {@link RequestQueue} instances provided by the {@link HttpCrawlerOptions.requestList}
194
- * or {@link HttpCrawlerOptions.requestQueue} constructor options, respectively.
186
+ * The source URLs are represented using {@link Request} objects that are fed from the
187
+ * {@link IRequestManager|request manager} provided via the {@link HttpCrawlerOptions.requestManager|`requestManager`}
188
+ * constructor option (a {@link RequestQueue} is itself a request manager). To read from a read-only source such
189
+ * as a {@link RequestList} while still being able to enqueue new requests, combine it with a queue into a
190
+ * {@link RequestManagerTandem} via {@link IRequestLoader.toTandem|`requestLoader.toTandem()`} and pass the
191
+ * result as `requestManager`.
195
192
  *
196
- * If both {@link HttpCrawlerOptions.requestList} and {@link HttpCrawlerOptions.requestQueue} are used,
197
- * the instance first processes URLs from the {@link RequestList} and automatically enqueues all of them
198
- * to {@link RequestQueue} before it starts their processing. This ensures that a single URL is not crawled multiple times.
193
+ * > The {@link HttpCrawlerOptions.requestList|`requestList`} and {@link HttpCrawlerOptions.requestQueue|`requestQueue`}
194
+ * > options are deprecated; they are still accepted and folded into a single `requestManager` for back-compat.
199
195
  *
200
196
  * The crawler finishes when there are no more {@link Request} objects to crawl.
201
197
  *
202
- * We can use the `preNavigationHooks` to adjust `gotOptions`:
198
+ * We can use the `preNavigationHooks` to adjust the crawling context before the request is made:
203
199
  *
204
200
  * ```javascript
205
201
  * preNavigationHooks: [
206
- * (crawlingContext, gotOptions) => {
202
+ * (crawlingContext) => {
207
203
  * // ...
208
204
  * },
209
205
  * ]
210
206
  * ```
211
207
  *
212
- * By default, this crawler only processes web pages with the `text/html`
213
- * and `application/xhtml+xml` MIME content types (as reported by the `Content-Type` HTTP header),
208
+ * By default, this crawler only processes web pages with the `text/html`, `application/xhtml+xml`, `text/xml`, `application/xml`,
209
+ * and `application/json` MIME content types (as reported by the `Content-Type` HTTP header),
214
210
  * and skips pages with other content types. If you want the crawler to process other content types,
215
211
  * use the {@link HttpCrawlerOptions.additionalMimeTypes} constructor option.
216
212
  * Beware that the parsing behavior differs for HTML, XML, JSON and other types of content.
217
213
  * For details, see {@link HttpCrawlerOptions.requestHandler}.
218
214
  *
219
- * New requests are only dispatched when there is enough free CPU and memory available,
220
- * using the functionality provided by the {@link AutoscaledPool} class.
221
- * All {@link AutoscaledPool} configuration options can be passed to the `autoscaledPoolOptions`
222
- * parameter of the constructor. For user convenience, the `minConcurrency` and `maxConcurrency`
223
- * {@link AutoscaledPool} options are available directly in the constructor.
215
+ * New requests are only dispatched when there is enough free CPU and memory available, as judged by the crawler's
216
+ * {@link ConcurrencySystem}.
217
+ * Concurrency is tuned via the `minConcurrency`, `maxConcurrency` and `maxRequestsPerMinute` options of the
218
+ * constructor, or, for finer control, by injecting a pre-configured
219
+ * {@link ConcurrencySystem|`concurrencySystem`}.
224
220
  *
225
221
  * **Example usage:**
226
222
  *
@@ -245,23 +241,9 @@ JSONData extends JsonValue = any> = RequestHandler<HttpCrawlingContext<UserData,
245
241
  * ```
246
242
  * @category Crawlers
247
243
  */
248
- export declare class HttpCrawler<Context extends InternalHttpCrawlingContext<any, any> = InternalHttpCrawlingContext, ContextExtension = {}, ExtendedContext extends Context = Context & ContextExtension> extends BasicCrawler<Context, ExtendedContext> {
249
- readonly config: Configuration;
250
- /**
251
- * A reference to the underlying {@link ProxyConfiguration} class that manages the crawler's proxies.
252
- * Only available if used by the crawler.
253
- */
254
- proxyConfiguration?: ProxyConfiguration;
255
- protected preNavigationHooks: InternalHttpHook<CrawlingContext>[];
256
- protected postNavigationHooks: ((crawlingContext: CrawlingContextWithReponse) => Awaitable<void>)[];
257
- protected persistCookiesPerSession: boolean;
258
- protected navigationTimeoutMillis: number;
259
- protected ignoreSslErrors: boolean;
260
- protected suggestResponseEncoding?: string;
261
- protected forceResponseEncoding?: string;
262
- protected additionalHttpErrorStatusCodes: Set<number>;
263
- protected ignoreHttpErrorStatusCodes: Set<number>;
264
- protected readonly supportedMimeTypes: Set<string>;
244
+ export declare class HttpCrawler<Context extends InternalHttpCrawlingContext<any, any> = InternalHttpCrawlingContext, ContextExtension = Dictionary<never>, ExtendedContext extends Context = Context & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<Context['request']>>> extends BasicCrawler<Context, ContextExtension, ExtendedContext, Routes> {
245
+ #private;
246
+ private ignoreSslErrors;
265
247
  protected static optionsShape: {
266
248
  // @ts-ignore optional peer dependency or compatibility with es2022
267
249
  navigationTimeoutSecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
@@ -274,13 +256,7 @@ export declare class HttpCrawler<Context extends InternalHttpCrawlingContext<any
274
256
  // @ts-ignore optional peer dependency or compatibility with es2022
275
257
  forceResponseEncoding: import("ow").StringPredicate & import("ow").BasePredicate<string | undefined>;
276
258
  // @ts-ignore optional peer dependency or compatibility with es2022
277
- proxyConfiguration: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
278
- // @ts-ignore optional peer dependency or compatibility with es2022
279
- persistCookiesPerSession: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
280
- // @ts-ignore optional peer dependency or compatibility with es2022
281
- additionalHttpErrorStatusCodes: import("ow").ArrayPredicate<number>;
282
- // @ts-ignore optional peer dependency or compatibility with es2022
283
- ignoreHttpErrorStatusCodes: import("ow").ArrayPredicate<number>;
259
+ saveResponseCookies: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
284
260
  // @ts-ignore optional peer dependency or compatibility with es2022
285
261
  preNavigationHooks: import("ow").ArrayPredicate<unknown> & import("ow").BasePredicate<unknown[] | undefined>;
286
262
  // @ts-ignore optional peer dependency or compatibility with es2022
@@ -305,28 +281,46 @@ export declare class HttpCrawler<Context extends InternalHttpCrawlingContext<any
305
281
  maxRequestRetries: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
306
282
  // @ts-ignore optional peer dependency or compatibility with es2022
307
283
  sameDomainDelaySecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
308
- // @ts-ignore optional peer dependency or compatibility with es2022
309
- maxSessionRotations: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
310
284
  // @ts-ignore optional peer dependency or compatibility with es2022
311
285
  maxRequestsPerCrawl: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
312
286
  // @ts-ignore optional peer dependency or compatibility with es2022
313
- autoscaledPoolOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
287
+ maxCrawlDepth: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
314
288
  // @ts-ignore optional peer dependency or compatibility with es2022
315
- sessionPoolOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
289
+ taskLoopOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
316
290
  // @ts-ignore optional peer dependency or compatibility with es2022
317
- useSessionPool: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
291
+ concurrencySystem: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
292
+ // @ts-ignore optional peer dependency or compatibility with es2022
293
+ sessionPool: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
294
+ // @ts-ignore optional peer dependency or compatibility with es2022
295
+ proxyConfiguration: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
318
296
  // @ts-ignore optional peer dependency or compatibility with es2022
319
297
  statusMessageLoggingInterval: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
320
298
  // @ts-ignore optional peer dependency or compatibility with es2022
321
299
  statusMessageCallback: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
300
+ // @ts-ignore optional peer dependency or compatibility with es2022
301
+ additionalHttpErrorStatusCodes: import("ow").ArrayPredicate<number>;
302
+ // @ts-ignore optional peer dependency or compatibility with es2022
303
+ ignoreHttpErrorStatusCodes: import("ow").ArrayPredicate<number>;
304
+ // @ts-ignore optional peer dependency or compatibility with es2022
305
+ blockedStatusCodes: import("ow").ArrayPredicate<number>;
322
306
  // @ts-ignore optional peer dependency or compatibility with es2022
323
307
  retryOnBlocked: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
324
308
  // @ts-ignore optional peer dependency or compatibility with es2022
325
- respectRobotsTxtFile: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
309
+ respectRobotsTxtFile: import("ow").AnyPredicate<boolean | object>;
310
+ // @ts-ignore optional peer dependency or compatibility with es2022
311
+ transactionalStorage: import("ow").BasePredicate<boolean | Partial<import("@crawlee/basic").StorageWritePolicy> | undefined>;
326
312
  // @ts-ignore optional peer dependency or compatibility with es2022
327
313
  onSkippedRequest: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
328
314
  // @ts-ignore optional peer dependency or compatibility with es2022
329
315
  httpClient: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
316
+ // @ts-ignore optional peer dependency or compatibility with es2022
317
+ configuration: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
318
+ // @ts-ignore optional peer dependency or compatibility with es2022
319
+ storageBackend: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
320
+ // @ts-ignore optional peer dependency or compatibility with es2022
321
+ eventManager: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
322
+ // @ts-ignore optional peer dependency or compatibility with es2022
323
+ logger: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
330
324
  // @ts-ignore optional peer dependency or compatibility with es2022
331
325
  minConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
332
326
  // @ts-ignore optional peer dependency or compatibility with es2022
@@ -336,135 +330,56 @@ export declare class HttpCrawler<Context extends InternalHttpCrawlingContext<any
336
330
  // @ts-ignore optional peer dependency or compatibility with es2022
337
331
  keepAlive: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
338
332
  // @ts-ignore optional peer dependency or compatibility with es2022
339
- log: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
340
- // @ts-ignore optional peer dependency or compatibility with es2022
341
- experiments: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
333
+ statistics: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
342
334
  // @ts-ignore optional peer dependency or compatibility with es2022
343
- statisticsOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
335
+ id: import("ow").StringPredicate & import("ow").BasePredicate<string | undefined>;
344
336
  };
345
337
  /**
346
338
  * All `HttpCrawlerOptions` parameters are passed via an options object.
347
339
  */
348
- constructor(options?: HttpCrawlerOptions<Context, ExtendedContext> & RequireContextPipeline<InternalHttpCrawlingContext, Context>, config?: Configuration);
340
+ constructor(options?: HttpCrawlerOptions<Context, ContextExtension, ExtendedContext> & RequireContextPipeline<InternalHttpCrawlingContext, Context>);
341
+ protected getNavigationTimeoutMillis(): number;
342
+ /**
343
+ * Folds {@link HTTP_OPTIMIZED_CONCURRENCY_SYSTEM_OPTIONS} into the default system, keeping the user's
344
+ * concurrency shortcuts on top. Not called for a supplied
345
+ * {@link BasicCrawlerOptions.concurrencySystem|`concurrencySystem`} — spread the constant into it yourself to
346
+ * keep the tuning.
347
+ */
348
+ protected createDefaultConcurrencySystem(options: ConcurrencySystemOptions): ConcurrencySystem;
349
349
  protected buildContextPipeline(): ContextPipeline<CrawlingContext, InternalHttpCrawlingContext>;
350
- private prepareProxyInfo;
350
+ private prepareHttpRequest;
351
351
  private makeHttpRequest;
352
352
  private processHttpResponse;
353
353
  private handleBlockedRequestByContent;
354
354
  protected isRequestBlocked(crawlingContext: InternalHttpCrawlingContext): Promise<string | false>;
355
- /**
356
- * Sets the cookie header to `gotOptions` based on the provided request and session headers, as well as any changes that occurred due to hooks.
357
- */
358
- protected _applyCookies({ session, request }: CrawlingContext, gotOptions: OptionsInit, preHookCookies: string, postHookCookies: string): void;
359
355
  /**
360
356
  * Function to make the HTTP request. It performs optimizations
361
357
  * on the request such as only downloading the request body if the
362
358
  * received content type matches text/html, application/xml, application/xhtml+xml.
363
359
  */
364
- protected _requestFunction({ request, session, proxyUrl, gotOptions, }: RequestFunctionOptions): Promise<PlainResponse>;
360
+ private requestFunction;
365
361
  /**
366
362
  * Encodes and parses response according to the provided content type
367
363
  */
368
- private _parseResponse;
364
+ private parseResponse;
369
365
  /**
370
366
  * Combines the provided `requestOptions` with mandatory (non-overridable) values.
371
367
  */
372
- protected _getRequestOptions(request: Request, session?: Session, proxyUrl?: string, gotOptions?: OptionsInit): {
373
- url?: string | URL | undefined;
374
- // @ts-ignore optional peer dependency or compatibility with es2022
375
- headers?: import("got-scraping").Headers | undefined;
376
- // @ts-ignore optional peer dependency or compatibility with es2022
377
- body?: string | Buffer | Readable | Generator | AsyncGenerator | import("form-data-encoder").FormDataLike | undefined;
378
- json?: unknown;
379
- // @ts-ignore optional peer dependency or compatibility with es2022
380
- request?: import("got-scraping").RequestFunction | undefined;
381
- // @ts-ignore optional peer dependency or compatibility with es2022
382
- agent?: import("got-scraping").Agents | undefined;
383
- // @ts-ignore optional peer dependency or compatibility with es2022
384
- h2session?: import("http2").ClientHttp2Session | undefined;
385
- decompress?: boolean | undefined;
386
- // @ts-ignore optional peer dependency or compatibility with es2022
387
- timeout?: import("got-scraping").Delays | undefined;
388
- prefixUrl?: string | URL | undefined;
389
- form?: Record<string, any> | undefined;
390
- // @ts-ignore optional peer dependency or compatibility with es2022
391
- cookieJar?: import("got-scraping").PromiseCookieJar | import("got-scraping").ToughCookieJar | undefined;
392
- signal?: AbortSignal | undefined;
393
- ignoreInvalidCookies?: boolean | undefined;
394
- // @ts-ignore optional peer dependency or compatibility with es2022
395
- searchParams?: string | import("got-scraping").SearchParameters | URLSearchParams | undefined;
396
- // @ts-ignore optional peer dependency or compatibility with es2022
397
- dnsLookup?: import("cacheable-lookup").default["lookup"] | undefined;
398
- // @ts-ignore optional peer dependency or compatibility with es2022
399
- dnsCache?: import("cacheable-lookup").default | boolean | undefined;
400
- context?: Record<string, unknown> | undefined;
401
- // @ts-ignore optional peer dependency or compatibility with es2022
402
- followRedirect?: boolean | ((response: import("got-scraping").PlainResponse) => boolean) | undefined;
403
- maxRedirects?: number | undefined;
404
- // @ts-ignore optional peer dependency or compatibility with es2022
405
- cache?: string | import("cacheable-request").StorageAdapter | boolean | undefined;
406
- throwHttpErrors?: boolean | undefined;
407
- username?: string | undefined;
408
- password?: string | undefined;
409
- http2?: boolean | undefined;
410
- allowGetBody?: boolean | undefined;
411
- methodRewriting?: boolean | undefined;
412
- // @ts-ignore optional peer dependency or compatibility with es2022
413
- dnsLookupIpVersion?: import("got-scraping").DnsLookupIpVersion;
414
- // @ts-ignore optional peer dependency or compatibility with es2022
415
- parseJson?: import("got-scraping").ParseJsonFunction | undefined;
416
- // @ts-ignore optional peer dependency or compatibility with es2022
417
- stringifyJson?: import("got-scraping").StringifyJsonFunction | undefined;
418
- localAddress?: string | undefined;
419
- method?: Method | undefined;
420
- // @ts-ignore optional peer dependency or compatibility with es2022
421
- createConnection?: import("got-scraping").CreateConnectionFunction | undefined;
422
- // @ts-ignore optional peer dependency or compatibility with es2022
423
- cacheOptions?: import("got-scraping").CacheOptions | undefined;
424
- // @ts-ignore optional peer dependency or compatibility with es2022
425
- https?: import("got-scraping").HttpsOptions | undefined;
426
- encoding?: BufferEncoding | undefined;
427
- resolveBodyOnly?: boolean | undefined;
428
- isStream?: boolean | undefined;
429
- // @ts-ignore optional peer dependency or compatibility with es2022
430
- responseType?: import("got-scraping").ResponseType | undefined;
431
- // @ts-ignore optional peer dependency or compatibility with es2022
432
- pagination?: import("got-scraping").PaginationOptions<unknown, unknown> | undefined;
433
- setHost?: boolean | undefined;
434
- maxHeaderSize?: number | undefined;
435
- enableUnixSockets?: boolean | undefined;
436
- } & {
437
- // @ts-ignore optional peer dependency or compatibility with es2022
438
- hooks?: Partial<import("got-scraping").Hooks>;
439
- // @ts-ignore optional peer dependency or compatibility with es2022
440
- retry?: Partial<import("got-scraping").RetryOptions>;
441
- // @ts-ignore optional peer dependency or compatibility with es2022
442
- } & import("got-scraping").Context & Required<Pick<OptionsInit, "url">> & {
443
- isStream: true;
444
- };
445
- protected _encodeResponse(request: Request, response: IncomingMessage, encoding: BufferEncoding): {
446
- encoding: BufferEncoding;
447
- response: IncomingMessage;
448
- };
368
+ private getRequestOptions;
369
+ private encodeResponse;
449
370
  /**
450
371
  * Checks and extends supported mime types
451
372
  */
452
- protected _extendSupportedMimeTypes(additionalMimeTypes: (string | RequestLike | ResponseLike)[]): void;
373
+ private extendSupportedMimeTypes;
453
374
  /**
454
375
  * Handles timeout request
455
376
  */
456
- protected _handleRequestTimeout(session?: Session): void;
457
- private _abortDownloadOfBody;
377
+ private handleRequestTimeout;
378
+ private abortDownloadOfBody;
458
379
  /**
459
380
  * @internal wraps public utility for mocking purposes
460
381
  */
461
- private _requestAsBrowser;
462
- }
463
- interface RequestFunctionOptions {
464
- request: Request;
465
- session?: Session;
466
- proxyUrl?: string;
467
- gotOptions: OptionsInit;
382
+ private requestAsBrowser;
468
383
  }
469
384
  /**
470
385
  * Creates new {@link Router} instance that works based on request labels.
@@ -490,7 +405,7 @@ interface RequestFunctionOptions {
490
405
  * await crawler.run();
491
406
  * ```
492
407
  */
493
- // @ts-ignore optional peer dependency or compatibility with es2022
494
- export declare function createHttpRouter<Context extends HttpCrawlingContext = HttpCrawlingContext, UserData extends Dictionary = GetUserDataFromRequest<Context['request']>>(routes?: RouterRoutes<Context, UserData>): import("@crawlee/basic").RouterHandler<Context>;
408
+ export declare function createHttpRouter<Context extends HttpCrawlingContext = HttpCrawlingContext, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<Context['request']>>>(routes?: RouterRoutes<Context, Routes>): RouterHandler<Context, Routes>;
409
+ export declare function createHttpRouter<Context extends HttpCrawlingContext = HttpCrawlingContext, UserData extends Dictionary = GetUserDataFromRequest<Context['request']>>(routes?: RouterRoutes<Context, Record<string, UserData>>): RouterHandler<Context, Record<string, UserData>>;
410
+ export declare function createHttpRouter<Context extends HttpCrawlingContext = HttpCrawlingContext, const Schemas extends RouteSchemas = RouteSchemas>(schemas: Schemas): RouterHandler<Context, RoutesFromSchemas<Schemas>>;
495
411
  export {};
496
- //# sourceMappingURL=http-crawler.d.ts.map