@crawlee/http 4.0.0-beta.216 → 4.0.0-beta.218

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.
@@ -3,7 +3,7 @@ import util from 'node:util';
3
3
  import { BasicCrawler, ContextPipeline, getCookiesFromResponse, NavigationSkippedError, remainingNavigationWindowMillis, RequestState, RequestThrottledError, Router, SessionError, } from '@crawlee/basic';
4
4
  import { ResponseWithUrl } from '@crawlee/http-client';
5
5
  import { parseArgument, RETRY_CSS_SELECTORS, schemas } from '@crawlee/utils/internal';
6
- import contentTypeParser from 'content-type';
6
+ import { isTypeValid, parse as parseContentType } from 'content-type';
7
7
  import iconv from 'iconv-lite';
8
8
  import { z } from 'zod';
9
9
  import { addTimeoutToPromise, storage, TimeoutError, tryCancel } from '@apify/timeout';
@@ -488,13 +488,11 @@ export class HttpCrawler extends BasicCrawler {
488
488
  this.#supportedMimeTypes.add(mimeType);
489
489
  continue;
490
490
  }
491
- try {
492
- const parsedType = contentTypeParser.parse(mimeType);
493
- this.#supportedMimeTypes.add(parsedType.type);
494
- }
495
- catch (err) {
491
+ const parsedType = parseContentType(mimeType);
492
+ if (!isTypeValid(parsedType.type)) {
496
493
  throw new Error(`Can not parse mime type ${mimeType} from "options.additionalMimeTypes".`);
497
494
  }
495
+ this.#supportedMimeTypes.add(parsedType.type);
498
496
  }
499
497
  }
500
498
  /**
@@ -1,7 +1,7 @@
1
1
  import { extname } from 'node:path';
2
2
  import { Readable } from 'node:stream';
3
3
  import { applySearchParams, parseArgument } from '@crawlee/utils/internal';
4
- import contentTypeParser from 'content-type';
4
+ import { isTypeValid, parse as parseContentType } from 'content-type';
5
5
  import mime from 'mime-types';
6
6
  import { z } from 'zod';
7
7
  const responseWithUrlSchema = z.looseObject({ url: z.url(), headers: z.looseObject({}) });
@@ -59,18 +59,16 @@ export function parseContentTypeFromResponse(response) {
59
59
  const { url, headers } = response;
60
60
  let parsedContentType;
61
61
  if (headers.get('content-type')) {
62
- try {
63
- parsedContentType = contentTypeParser.parse(headers.get('content-type'));
64
- }
65
- catch {
66
- // Can not parse content type from Content-Type header. Try to parse it from file extension.
67
- }
62
+ const parsed = parseContentType(headers.get('content-type'));
63
+ // Can not parse content type from Content-Type header. Try to parse it from file extension.
64
+ if (isTypeValid(parsed.type))
65
+ parsedContentType = parsed;
68
66
  }
69
67
  // Parse content type from file extension as fallback
70
68
  if (!parsedContentType) {
71
69
  const parsedUrl = new URL(url);
72
70
  const contentTypeFromExtname = mime.contentType(extname(parsedUrl.pathname)) || 'application/octet-stream; charset=utf-8'; // Fallback content type, specified in https://tools.ietf.org/html/rfc7231#section-3.1.1.5
73
- parsedContentType = contentTypeParser.parse(contentTypeFromExtname);
71
+ parsedContentType = parseContentType(contentTypeFromExtname);
74
72
  }
75
73
  return {
76
74
  type: parsedContentType.type,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/http",
3
- "version": "4.0.0-beta.216",
3
+ "version": "4.0.0-beta.218",
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.13.0"
@@ -49,14 +49,13 @@
49
49
  "dependencies": {
50
50
  "@apify/timeout": "^1.0.1",
51
51
  "@apify/utilities": "^3.0.1",
52
- "@crawlee/basic": "4.0.0-beta.216",
53
- "@crawlee/core": "4.0.0-beta.216",
54
- "@crawlee/http-client": "4.0.0-beta.216",
55
- "@crawlee/types": "4.0.0-beta.216",
56
- "@crawlee/utils": "4.0.0-beta.216",
57
- "@types/content-type": "^1.1.8",
52
+ "@crawlee/basic": "4.0.0-beta.218",
53
+ "@crawlee/core": "4.0.0-beta.218",
54
+ "@crawlee/http-client": "4.0.0-beta.218",
55
+ "@crawlee/types": "4.0.0-beta.218",
56
+ "@crawlee/utils": "4.0.0-beta.218",
58
57
  "cheerio": "^1.0.0",
59
- "content-type": "^1.0.5",
58
+ "content-type": "^3.1.1",
60
59
  "iconv-lite": "^0.7.2",
61
60
  "mime-types": "^3.0.1",
62
61
  "tslib": "^2.8.1",
@@ -70,5 +69,5 @@
70
69
  }
71
70
  }
72
71
  },
73
- "gitHead": "0faae75ba532836e8510f0733893e754ea3f823f"
72
+ "gitHead": "53560afb8d133a1a08b95cda31c83f988f0b1429"
74
73
  }