Support non-utf8 charsets

This commit is contained in:
Gregory Schier
2024-09-05 13:58:06 -07:00
parent 3601410fb8
commit fedf356576
2 changed files with 16 additions and 2 deletions

View File

@@ -46,3 +46,8 @@ export function modelsEq(a: Model, b: Model) {
export function getContentTypeHeader(headers: HttpResponseHeader[]): string | null {
return headers.find((h) => h.name.toLowerCase() === 'content-type')?.value ?? null;
}
export function getCharsetFromContentType(headers: HttpResponseHeader[]): string | null {
const contentType = getContentTypeHeader(headers);
return contentType?.match(/charset=([^ ;]+)/)?.[1] ?? null;
}