Skip to content

Commit 63bfb12

Browse files
committed
feat: pass matching mime type to xmldom
If the `Content-Type` header contains one of the mime types supported by `DOMParser`, the first matching mime type will be used instead of `text/xml`. The default is still `text/xml` for cases when the header is not present or none of the mime types from the list are present.
1 parent 152b8e9 commit 63bfb12

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

services/dynamic/dynamic-xml.service.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DOMParser } from '@xmldom/xmldom'
1+
import { DOMParser, MIME_TYPE } from '@xmldom/xmldom'
22
import xpath from 'xpath'
33
import { MetricNames } from '../../core/base-service/metric-helper.js'
44
import { renderDynamicBadge, httpErrors } from '../dynamic-common.js'
@@ -10,6 +10,8 @@ import {
1010
} from '../index.js'
1111
import { createRoute } from './dynamic-helpers.js'
1212

13+
const MIME_TYPES = Object.values(MIME_TYPE)
14+
1315
const description = `
1416
The Dynamic XML Badge allows you to extract an arbitrary value from any
1517
XML Document using an XPath selector and show it on a badge.
@@ -136,11 +138,10 @@ export default class DynamicXml extends BaseService {
136138
})
137139

138140
let contentType = 'text/xml'
139-
if (
140-
res.headers['content-type'] &&
141-
res.headers['content-type'].includes('text/html')
142-
) {
143-
contentType = 'text/html'
141+
if (res.headers['content-type']) {
142+
contentType =
143+
MIME_TYPES.find(mime => res.headers['content-type'].includes(mime)) ??
144+
'text/xml'
144145
}
145146

146147
const { values: value } = this.transform({

0 commit comments

Comments
 (0)