I am trying to add a \"Referer\"-HTTP-Header to certain AJAX requests in my Chrome extension. You can\'t change it directly in the AJAX request so I tried to change it using
The reason you can't set the Referrer header when you don't have a blocking request is that the request has potentially already gone out - you are being notified asynchronously, and cannot change anything about the request.
To change headers, I use this code:
function mod_headers(header_array,p_name,p_value) {
var did_set = false;
for(var i in header_array) {
var header = header_array[i];
var name = header.name;
var value = header.value;
// If the header is already present, change it:
if(name == p_name) {
header.value = p_value;
did_set = true;
}
}
// if it is not, add it:
if(!did_set) { header_array.push( { name : p_name , value : p_value } ); }
}