@crawlee/http 4.0.0-beta.12 → 4.0.0-beta.121

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