This repo is for distribution on bower. The source for this module is in the
main angular-hu-headers repo.
Please file issues and pull requests against that repo.
Add custom, application headers, to every $httpresponse. Currently, two headers are added:
httpu-request-time: The time the request took to completehttpu-request-url: The url used, with all the parametershttpu-cached-at: The time a cached request was added to the cache specified in$http
Get it from bower or directly download it.
bower install --save angular-hu-headersAdd the dependency in the HTML
<scripttype="text/javascript" src="bower_components/angular-hu-headers/headers.js"></script>Add the httpu.headers dependency to your App Module
angular.module('MyApp',['httpu.headers']);angular.module('MyApp').factory('myCache',function(huFromCache,$cacheFactory){varcache=$cacheFactory('apicache');returnhuFromCache(cache);}).run(function($http,myCache){//Make a timestamped request, and cache response for id=5. timestamp param will be removed$http.get('http://myapi.com/things',{params: {id: 5},cache: myCache}).then(function(response){console.log('The request was to the endopoint: ',response.headers('httpu-request-url'));console.log('The request took ',response.headers('httpu-request-time')+'ms');console.log('The request was cached at',response.headers('httpu-cached-at')+'ms');//'The request was to the endopoint: http://myapi.com/things?id=5//'The request took 123ms//'The request was cached at 1431335511216ms});});- You want to know the final URL used for your request (this may be computed by $http before leaving to $httpBackend) to delete cache entries, log them...
- You wanna know if the request you performed hit your
$httprequest cache - Wanna collect statistics information for your backend responses accessed over the worldwide clients.
Angular $httpBackend has been decorated, due to cross-browser incompatibilities reached while decorating window.XMLHTTPRequest.
The MIT License (MIT)
Copyright (c) 2015 Telefónica I+D - http://www.tid.es