Delete headers from Angular.js $http request

angularjs, http, http-headers

Solution

If you use the unminified version of Angular, you'll get nicer backtraces when an exception happens, and you'll have an easier time introspecting the angular code. I personally recommend it while developing. Here's what `headersGetter` actually looks like:

function (name) {
    if (!headersObj) headersObj =  parseHeaders(headers);

    if (name) {
      return headersObj[lowercase(name)] || null;
    }

    return headersObj;
  } 

The `data` argument to your transformer will be undefined unless you’re POSTing some data.

The `headersGetter` function takes an optional argument `name`, if you want to get a single header, but you omit the argument to set a header:

headersGetter()['Cache-Control'] = 'no-cache';
headersGetter()['X-Requested-With'] = '';

The return value from your transformer should be the value of `data` you want to use.

You can’t change the `Referer` header from XHR.

Problem

I want to delete some `$http` request header fields from one specific request (it means not on the `$httpProvider` level). These fields are: - Cache-Control - If-Modified-Since - Referer - X-Requested-With How to do this in a single request? I tried to use `transformRequest` parameter, but didn't find enough information to make it work. Such a [CoffeeScript] code: ``` $scope.logout = -> $http({ method: 'GET' url: '/api/logout' headers: { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' } transformRequest: (data, headersGetter) -> console.log data console.log headersGetter data }).success -> $location.path('editor') ``` shows that `data` is `undefined`, headersGetter is `function (c){a||(a=Nb(b));return c?a[y(c)]||null:a}` (which says to me absolutely nothing), and I didn't understand what to return from the transformRequest function.

Original source