@crawlee/http 4.0.0-beta.216 → 4.0.0-beta.217
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.
- package/internals/http-crawler.js +4 -6
- package/internals/utils.js +6 -8
- package/package.json +8 -9
|
@@ -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
|
|
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
|
-
|
|
492
|
-
|
|
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
|
/**
|
package/internals/utils.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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 =
|
|
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.
|
|
3
|
+
"version": "4.0.0-beta.217",
|
|
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.
|
|
53
|
-
"@crawlee/core": "4.0.0-beta.
|
|
54
|
-
"@crawlee/http-client": "4.0.0-beta.
|
|
55
|
-
"@crawlee/types": "4.0.0-beta.
|
|
56
|
-
"@crawlee/utils": "4.0.0-beta.
|
|
57
|
-
"@types/content-type": "^1.1.8",
|
|
52
|
+
"@crawlee/basic": "4.0.0-beta.217",
|
|
53
|
+
"@crawlee/core": "4.0.0-beta.217",
|
|
54
|
+
"@crawlee/http-client": "4.0.0-beta.217",
|
|
55
|
+
"@crawlee/types": "4.0.0-beta.217",
|
|
56
|
+
"@crawlee/utils": "4.0.0-beta.217",
|
|
58
57
|
"cheerio": "^1.0.0",
|
|
59
|
-
"content-type": "^1.
|
|
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": "
|
|
72
|
+
"gitHead": "419bbc19902f65caf584ddfb0f26a901f5f157c4"
|
|
74
73
|
}
|