Skip to content

Commit 435536b

Browse files
authored
Merge pull request #56 from github/fix-checking-of-accept-header
Fix checking of accept header
2 parents 585ef48 + 9c01686 commit 435536b

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

include-fragment-element.js

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

test/test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ const responses = {
4141
})
4242
},
4343
'/fragment': function(request) {
44-
if (request.headers.get('Accept') === 'text/html; fragment') {
44+
if (request.headers.get('Accept') === 'text/fragment+html') {
4545
return new Response('<div id="fragment">fragment</div>', {
4646
status: 200,
4747
headers: {
48-
'Content-Type': 'text/html; fragment'
48+
'Content-Type': 'text/fragment+html'
4949
}
5050
})
5151
} else {
@@ -197,15 +197,15 @@ suite('include-fragment-element', function() {
197197

198198
test('throws on non-matching Content-Type', function() {
199199
const el = document.createElement('include-fragment')
200-
el.setAttribute('accept', 'text/html; fragment')
200+
el.setAttribute('accept', 'text/fragment+html')
201201
el.setAttribute('src', '/hello')
202202

203203
return el.data.then(
204204
() => {
205205
assert.ok(false)
206206
},
207207
error => {
208-
assert.match(error, /expected text\/html; fragment but was text\/html; charset=utf-8/)
208+
assert.match(error, /expected text\/fragment\+html but was text\/html; charset=utf-8/)
209209
}
210210
)
211211
})
@@ -309,7 +309,7 @@ suite('include-fragment-element', function() {
309309

310310
test('replaces with response with the right accept header', function() {
311311
const div = document.createElement('div')
312-
div.innerHTML = '<include-fragment src="/fragment" accept="text/html; fragment">loading</include-fragment>'
312+
div.innerHTML = '<include-fragment src="/fragment" accept="text/fragment+html">loading</include-fragment>'
313313
document.body.appendChild(div)
314314

315315
return when(div.firstChild, 'load').then(() => {

0 commit comments

Comments
 (0)