Skip to content

Commit 6dc7867

Browse files
committed
Support any Accept header
1 parent 2e31ffd commit 6dc7867

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

include-fragment-element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export default class IncludeFragmentElement extends HTMLElement {
127127
throw new Error(`Failed to load resource: the server responded with a status of ${response.status}`)
128128
}
129129
const ct = response.headers.get('Content-Type')
130-
if (!ct || !ct.match(this.accept ? this.accept : /^text\/html/)) {
130+
if (this.accept !== '*/*' && (!ct || !ct.match(this.accept ? this.accept : /^text\/html/))) {
131131
throw new Error(`Failed to load resource: expected ${this.accept || 'text/html'} but was ${ct}`)
132132
}
133133
return response

test/test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,17 @@ suite('include-fragment-element', function() {
282282
})
283283
})
284284

285+
test('replaces with response with accept header for any', function() {
286+
const div = document.createElement('div')
287+
div.innerHTML = '<include-fragment src="/test.js" accept="*/*">loading</include-fragment>'
288+
document.body.appendChild(div)
289+
290+
return when(div.firstChild, 'load').then(() => {
291+
assert.equal(document.querySelector('include-fragment'), null)
292+
assert.match(document.body.textContent, /alert\("what"\)/)
293+
})
294+
})
295+
285296
test('replaces with response with the right accept header', function() {
286297
const div = document.createElement('div')
287298
div.innerHTML = '<include-fragment src="/fragment" accept="text/html; fragment">loading</include-fragment>'

0 commit comments

Comments
 (0)