Skip to content

Commit f229fdf

Browse files
Handle correctly custom encodings when fetching
1 parent 390d56f commit f229fdf

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/archivist/fetcher/htmlOnlyFetcher.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import AbortController from 'abort-controller';
2+
import convertBody from 'fetch-charset-detection';
23
import HttpProxyAgent from 'http-proxy-agent';
34
import HttpsProxyAgent from 'https-proxy-agent';
45
import nodeFetch, { AbortError } from 'node-fetch';
@@ -31,13 +32,13 @@ export default async function fetch(url, configuration) {
3132
}
3233

3334
const mimeType = response.headers.get('content-type');
34-
35+
const responseBuffer = await response.arrayBuffer();
3536
let content;
3637

3738
if (mimeType.startsWith('text/')) {
38-
content = await response.text();
39+
content = convertBody(responseBuffer, response.headers);
3940
} else {
40-
content = Buffer.from(await response.arrayBuffer());
41+
content = Buffer.from(responseBuffer);
4142
}
4243

4344
if (!content) {

0 commit comments

Comments
 (0)