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 @@ ...@@ -8,11 +8,17 @@
if (gl.startup_calls && window.fetch) { if (gl.startup_calls && window.fetch) {
Object.keys(gl.startup_calls).forEach(apiCall => { Object.keys(gl.startup_calls).forEach(apiCall => {
// fetch won’t send cookies in older browsers, unless you set the credentials init option. gl.startup_calls[apiCall] = {
// We set to `same-origin` which is default value in modern browsers. fetchCall: fetch(apiCall, {
// See https://github.com/whatwg/fetch/pull/585 for more information. // Emulate XHR for Rails AJAX request checks
gl.startup_calls[apiCall] = { headers: {
fetchCall: fetch(apiCall, { credentials: 'same-origin' }) '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