Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@kikobeats/time-span": "~1.0.13",
"@metascraper/helpers": "~5.56.2",
"cheerio": "~1.2.0",
"content-type": "~1.0.5",
"content-type": "~3.0.0",
"css-url-regex": "~4.0.0",
"debug-logfmt": "~1.4.12",
"execall": "~2.0.0",
Expand Down
14 changes: 4 additions & 10 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,18 @@ const SEPARATOR = /,|\r?\n/

const parseContentType = contentType => {
if (typeof contentType !== 'string') return UNKNOWN_CONTENT_TYPE
try {
return parse(contentType.split(SEPARATOR)[0])
} catch {
return UNKNOWN_CONTENT_TYPE
}
const parsed = parse(contentType.split(SEPARATOR)[0])
return parsed.type?.includes('/') ? parsed : UNKNOWN_CONTENT_TYPE
}

const contentType = headers => {
const contentType = headers['content-type']
return (
CACHE[contentType] || (CACHE[contentType] = parseContentType(contentType))
)
return CACHE[contentType] || (CACHE[contentType] = parseContentType(contentType))
}

const getContentType = headers => contentType(headers).type

const getCharset = headers =>
contentType(headers).parameters.charset?.toLowerCase()
const getCharset = headers => contentType(headers).parameters.charset?.toLowerCase()

const getContentLength = headers => Number(headers['content-length'])

Expand Down