File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,18 @@ export default class IncludeFragmentElement extends HTMLElement {
65
65
}
66
66
}
67
67
68
+ get accept ( ) {
69
+ return this . getAttribute ( 'accept' )
70
+ }
71
+
72
+ set accept ( val ) {
73
+ if ( val ) {
74
+ this . setAttribute ( 'accept' , val )
75
+ } else {
76
+ this . removeAttribute ( 'accept' )
77
+ }
78
+ }
79
+
68
80
get data ( ) {
69
81
return getData ( this )
70
82
}
@@ -99,7 +111,7 @@ export default class IncludeFragmentElement extends HTMLElement {
99
111
method : 'GET' ,
100
112
credentials : 'same-origin' ,
101
113
headers : {
102
- Accept : 'text/html'
114
+ Accept : this . accept || 'text/html'
103
115
}
104
116
} )
105
117
}
@@ -115,8 +127,8 @@ export default class IncludeFragmentElement extends HTMLElement {
115
127
throw new Error ( `Failed to load resource: the server responded with a status of ${ response . status } ` )
116
128
}
117
129
const ct = response . headers . get ( 'Content-Type' )
118
- if ( ! ct || ! ct . match ( / ^ t e x t \/ h t m l / ) ) {
119
- throw new Error ( `Failed to load resource: expected text/html but was ${ ct } ` )
130
+ if ( ! ct || ! ct . match ( this . accept ? this . accept : / ^ t e x t \/ h t m l / ) ) {
131
+ throw new Error ( `Failed to load resource: expected ${ this . accept || ' text/html' } but was ${ ct } ` )
120
132
}
121
133
return response
122
134
} )
You can’t perform that action at this time.
0 commit comments