feat: better media types detection for JSON, XML and HTML lenses (#1438)

Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
Co-authored-by: Liyas Thomas <liyascthomas@gmail.com>
This commit is contained in:
Kévin Dunglas
2021-01-26 05:27:11 +01:00
committed by GitHub
parent d2dfb4c8df
commit 07f370d6d2
9 changed files with 37 additions and 45 deletions

View File

@@ -7,22 +7,13 @@ import xmlLens from "./xmlLens"
export const lenses = [jsonLens, imageLens, htmlLens, xmlLens, rawLens]
export function getSuitableLenses(response) {
if (!response || !response.headers || !response.headers["content-type"])
return [rawLens]
const result = []
if (response && response.headers && response.headers["content-type"]) {
const properContentType = response.headers["content-type"].split(";")[0]
for (const lens of lenses) {
if (
lens.supportedContentTypes === null ||
lens.supportedContentTypes.includes(properContentType)
) {
result.push(lens)
}
}
} else {
// We don't know the content type, so lets just add rawLens
result.push(rawLens)
for (const lens of lenses) {
if (lens.isSupportedContentType(response.headers["content-type"]))
result.push(lens)
}
return result