使用 "whenPost - respond" 方法时访问 Angular $htttpBackend中的"header"



我正在使用$httpBackend模拟后端,我想在收到请求时访问标头:

$httpBackend.whenPOST('/movies').respond(function(method, url, data) {
    // How do I get access to the headers.
    // I want to check the headers and retrieve a token.
    var params = angular.fromJson(data),
        movie = MoviesDataModel.addOne(params),
        movieId = movie.id; // get the id of the new resource to populate the Location field
    return [201, movie, { Location: '/movies/' + movieId }];
});

基本上,我想在发送数据之前检查头中的值。

有什么想法吗?

从手动中获得

httpBackend.whenPOST('/movies',data, function(headers){
  return headers['Authorization'] == 'xxx';
})
.respond(function(method, url, data) {