I want to delete some $http
request header fields from one specific request (it means not on the $httpProvider
level). These fields are:
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.
Guidelines. The dp:remove-http-request-header element removes a specific header field and its associated value from the protocol header of a client request. When the client request contains the header field identified by the field attribute, removes this header field from the client request.
To add or overwrite these defaults, simply add or remove a property from these configuration objects. To add headers for an HTTP method other than POST or PUT, simply add a new object with the lowercased HTTP method name as the key, e.g. $httpProvider. defaults.
$http is an AngularJS service for reading data from remote servers.
HTTP Headers let the client and the server share additional information about the HTTP request or response. For example, we use the content-type header to indicate the media type of the resource like JSON, text, blob, etc.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With