Tweak getting content type

This commit is contained in:
Gregory Schier
2025-02-23 06:25:53 -08:00
parent dac2cec52f
commit 9d8b7a5265
8 changed files with 17 additions and 29 deletions

View File

@@ -36,12 +36,12 @@ export function modelsEq(a: AnyModel, b: AnyModel) {
return false;
}
export function getContentTypeHeader(headers: HttpResponseHeader[]): string | null {
return headers.find((h) => h.name.toLowerCase() === 'content-type')?.value ?? null;
export function getContentTypeFromHeaders(headers: HttpResponseHeader[] | null): string | null {
return headers?.find((h) => h.name.toLowerCase() === 'content-type')?.value ?? null;
}
export function getCharsetFromContentType(headers: HttpResponseHeader[]): string | null {
const contentType = getContentTypeHeader(headers);
const contentType = getContentTypeFromHeaders(headers);
if (contentType == null) return null;
const mimeType = getMimeTypeFromContentType(contentType);