Skip to content

Commit 6022b84

Browse files
committed
Performance improvement
Skip data parsing if charset is already given in the content-type header Fixes #305
1 parent 0fb2cbf commit 6022b84

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Diff for: source/utils/get-charset.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ export default function getCharset(content: Buffer, headers?: Headers) {
1919
charset = parseContentType(contentType);
2020
}
2121

22+
if (charset) {
23+
return charset;
24+
}
25+
2226
// No charset in content type, peek at response body for at most 1024 bytes
2327
const data = content.slice(0, 1024).toString();
2428

2529
// HTML5, HTML4 and XML
26-
if (!charset && data) {
30+
if (data) {
2731
const $ = load(data);
2832

2933
charset = parseContentType(

0 commit comments

Comments
 (0)