Skip to content

Commit

Permalink
UI-2017: generic remove header
Browse files Browse the repository at this point in the history
  • Loading branch information
k-anderson committed Jan 27, 2016
1 parent aff7749 commit eed8674
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions js/lib/monster.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ define(function(require){
},

_defineRequest: function(id, request, app){
if (request.hasOwnProperty('removeHeaders')) {
request.removeHeaders = $.map(request.removeHeaders, function(n,i){return n.toLowerCase();});
}
var self = this,
// If an apiRoot is defined, force it, otherwise takes either the apiUrl of the app, or the default api url
apiUrl = request.apiRoot ? request.apiRoot : (app.apiUrl ? app.apiUrl : this.config.api.default),
Expand All @@ -56,11 +59,14 @@ define(function(require){
before: function(ampXHR, settings) {
monster.pub('monster.requestStart');

if (!hasRemoveHeaders || (hasRemoveHeaders && request.removeHeaders.indexOf('X-Auth-Token') < 0)) {
if (!hasRemoveHeaders || (hasRemoveHeaders && request.removeHeaders.indexOf('x-auth-token') < 0)) {
ampXHR.setRequestHeader('X-Auth-Token', app.authToken);
}

_.each(request.headers, function(val, key) {
if (!hasRemoveHeaders || request.removeHeaders.indexOf(key.toLowerCase()) < 0) {
ampXHR.setRequestHeader(key, val);
}
ampXHR.setRequestHeader(key, val);
});

Expand All @@ -69,7 +75,7 @@ define(function(require){
};

if (hasRemoveHeaders) {
if (request.removeHeaders.indexOf('Content-Type') > -1) {
if (request.removeHeaders.indexOf('content-type') > -1) {
delete settings.contentType;
}
}
Expand Down

0 comments on commit eed8674

Please sign in to comment.