Give our requests the popular but non-standard X-Requested-With

header (r=crschmidt, closes #3491).
This commit is contained in:
Marc Jansen
2011-09-22 02:57:39 +02:00
parent 81cfbe2f80
commit 6b30856a07
2 changed files with 68 additions and 4 deletions

View File

@@ -122,6 +122,25 @@ OpenLayers.Request = {
{proxy: OpenLayers.ProxyHost}
);
config = OpenLayers.Util.applyDefaults(config, defaultConfig);
// Always set the "X-Requested-With" header to signal that this request
// was issued through the XHR-object. Since header keys are case
// insensitive and we want to allow overriding of the "X-Requested-With"
// header through the user we cannot use applyDefaults, but have to
// check manually whether we were called with a "X-Requested-With"
// header.
var customRequestedWithHeader = false;
for(headerKey in config.headers) {
if (config.headers.hasOwnProperty( headerKey )) {
if (headerKey.toLowerCase() === 'x-requested-with') {
customRequestedWithHeader = true;
}
}
}
if (customRequestedWithHeader === false) {
// we did not have a custom "X-Requested-With" header
config.headers['X-Requested-With'] = 'XMLHttpRequest';
}
// create request, open, and set headers
var request = new OpenLayers.Request.XMLHttpRequest();