Commit 5b10ead1 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Set X-Requested-With for startup JS requests

This is used by Rails to detect if the request is an AJAX request.
We do the same in our axios client.

Changelog: performance
parent a0ded336
......@@ -8,11 +8,17 @@
if (gl.startup_calls && window.fetch) {
Object.keys(gl.startup_calls).forEach(apiCall => {
// fetch won’t send cookies in older browsers, unless you set the credentials init option.
// We set to `same-origin` which is default value in modern browsers.
// See https://github.com/whatwg/fetch/pull/585 for more information.
gl.startup_calls[apiCall] = {
fetchCall: fetch(apiCall, { credentials: 'same-origin' })
gl.startup_calls[apiCall] = {
fetchCall: fetch(apiCall, {
// Emulate XHR for Rails AJAX request checks
headers: {
'X-Requested-With': 'XMLHttpRequest'
},
// fetch won’t send cookies in older browsers, unless you set the credentials init option.
// We set to `same-origin` which is default value in modern browsers.
// See https://github.com/whatwg/fetch/pull/585 for more information.
credentials: 'same-origin'
})
};
});
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment