diff options
| author | bolasblack | 2013-07-03 15:51:05 +0800 |
|---|---|---|
| committer | Igor Minar | 2013-07-08 08:55:20 -0700 |
| commit | a7150f1256f2a97a931b3c0d16eab70f45e81cae (patch) | |
| tree | b8c74445e77e116c7a8f0d726596ffc0ab40f2a1 /test/ng | |
| parent | 0d124e190b24e737405b467d4fc11f10047b3d9c (diff) | |
| download | angular.js-a7150f1256f2a97a931b3c0d16eab70f45e81cae.tar.bz2 | |
feat($http): accept function as headers value
So we can request with dynamic header value.
module.factory('Res', [
'$resource'
'$routeParams'
'globalConfig'
function($resource, $routeParams, globalConfig) {
resource('/url/:id', {id: "@id"}, {
patch: {
method: 'patch',
headers: {
'Authorization': function() {
return "token " + globalConfig.token;
}
}
}
});
}]);
Diffstat (limited to 'test/ng')
| -rw-r--r-- | test/ng/httpSpec.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/ng/httpSpec.js b/test/ng/httpSpec.js index 8f2642f3..c21c6c23 100644 --- a/test/ng/httpSpec.js +++ b/test/ng/httpSpec.js @@ -784,6 +784,28 @@ describe('$http', function() { $httpBackend.flush(); })); + + it('should send execute result if header value is function', inject(function() { + var headerConfig = {'Accept': function() { return 'Rewritten'; }}; + + function checkHeaders(headers) { + return headers['Accept'] == 'Rewritten'; + } + + $httpBackend.expect('GET', '/url', undefined, checkHeaders).respond(''); + $httpBackend.expect('POST', '/url', undefined, checkHeaders).respond(''); + $httpBackend.expect('PUT', '/url', undefined, checkHeaders).respond(''); + $httpBackend.expect('PATCH', '/url', undefined, checkHeaders).respond(''); + $httpBackend.expect('DELETE', '/url', undefined, checkHeaders).respond(''); + + $http({url: '/url', method: 'GET', headers: headerConfig}); + $http({url: '/url', method: 'POST', headers: headerConfig}); + $http({url: '/url', method: 'PUT', headers: headerConfig}); + $http({url: '/url', method: 'PATCH', headers: headerConfig}); + $http({url: '/url', method: 'DELETE', headers: headerConfig}); + + $httpBackend.flush(); + })); }); |
