@crawlee/http-client 4.0.0-beta.113 → 4.0.0-beta.115

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,5 +1,4 @@
1
- import type { BaseHttpClient as BaseHttpClientInterface, CrawleeLogger, SendRequestOptions, SessionFingerprint } from '@crawlee/types';
2
- import { CookieJar } from 'tough-cookie';
1
+ import type { BaseHttpClient as BaseHttpClientInterface, CookieJar, CrawleeLogger, SendRequestOptions, SessionFingerprint } from '@crawlee/types';
3
2
  /**
4
3
  * Per-request options handed to a concrete client's `fetch` implementation.
5
4
  */
@@ -1,4 +1,3 @@
1
- import { CookieJar } from 'tough-cookie';
2
1
  /**
3
2
  * Base HTTP client that provides fetch-like `sendRequest` with Crawlee-managed
4
3
  * behaviors (redirect handling, proxy and cookie handling). Concrete clients
@@ -48,17 +47,21 @@ export class BaseHttpClient {
48
47
  }
49
48
  }
50
49
  }
51
- resolveRequestContext(options) {
50
+ async resolveRequestContext(options) {
52
51
  const proxyUrl = options?.proxyUrl ?? options?.session?.proxyInfo?.url;
53
- const cookieJar = options?.cookieJar ?? options?.session?.cookieJar ?? new CookieJar();
52
+ const cookieJar = options?.cookieJar ?? options?.session?.cookieJar ?? (await this.#createDefaultCookieJar());
54
53
  const signal = this.createAbortSignal(options?.signal, options?.timeoutMillis);
55
54
  return {
56
55
  proxyUrl,
57
- cookieJar: cookieJar,
56
+ cookieJar,
58
57
  signal,
59
58
  fingerprint: options?.session?.fingerprint,
60
59
  };
61
60
  }
61
+ async #createDefaultCookieJar() {
62
+ const { CookieJar: ToughCookieJar } = await import('tough-cookie');
63
+ return new ToughCookieJar();
64
+ }
62
65
  createAbortSignal(signal, timeoutMillis) {
63
66
  if (signal && timeoutMillis) {
64
67
  return AbortSignal.any([signal, AbortSignal.timeout(timeoutMillis)]);
@@ -104,7 +107,7 @@ export class BaseHttpClient {
104
107
  const maxRedirects = 10;
105
108
  let currentRequest = initialRequest;
106
109
  let redirectCount = 0;
107
- const { proxyUrl, cookieJar, signal, fingerprint } = this.resolveRequestContext(options);
110
+ const { proxyUrl, cookieJar, signal, fingerprint } = await this.resolveRequestContext(options);
108
111
  currentRequest = initialRequest.clone();
109
112
  while (true) {
110
113
  await this.applyCookies(currentRequest, cookieJar);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/http-client",
3
- "version": "4.0.0-beta.113",
3
+ "version": "4.0.0-beta.115",
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"
@@ -47,7 +47,7 @@
47
47
  "access": "public"
48
48
  },
49
49
  "dependencies": {
50
- "@crawlee/types": "4.0.0-beta.113",
50
+ "@crawlee/types": "4.0.0-beta.115",
51
51
  "tough-cookie": "^6.0.0"
52
52
  },
53
53
  "lerna": {
@@ -57,5 +57,5 @@
57
57
  }
58
58
  }
59
59
  },
60
- "gitHead": "a80d4b05a84ecc651dcd68fafd7a1ff35e6e7532"
60
+ "gitHead": "9bb6f54b10a88a709f0461486601a98365a90403"
61
61
  }