This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Make dynamic headers work with @value annotation in $resource #7324
Open
Description
type: feature request
the idea would be to allow @value annotations in resource definitions like:
return $resource('my/api/url', {}, {
update: {method: 'PUT', headers: { 'If-Match': '@version' }},
});
i'm too new to javascript and to angularjs so i can't make a proper implementation but for now i hacked the /src/ngResource/resource.js file with the following code to make this work (inserted the custom code on line 557):
if (hasBody) httpConfig.data = data;
route.setUrlParams(httpConfig,
extend({}, extractParams(data, action.params || {}), params),
action.url);
//******************************************************
//custom code to make dynamic headers work
var getHeaders = function (config, params) {
var result = extend({}, config.headers);
var headerParams = extend({}, config.headers);
forEach(headerParams, function (value, key) {
if (value.charAt(0) == '@') {
result[key] = params[value.substr(1)];
}
});
return result;
}
httpConfig.headers = getHeaders(httpConfig, params);
//******************************************************
maybe someone can take this and make a proper implementation out of it