问题描述
采用了棱角分明JS的$资源服务,是否有指定的第二,第三等的。如果无 - 匹配和ETag头信息的方式资源的调查?
Using Angular JS's $resource service, is there a way to specify the If-None-Match and ETag headers for the 2nd, 3rd, etc polls of a resource?
var SummarySearch = $resource(<<apiurl>>,
{ },
{
get: {
method: 'GET',
headers: {
'x-header': 'id'
}
}
});
我已经得到此项为设定恒定头的工作(这只是 X-头:ID
在这种情况下),但我需要的东西,每个请求的变化,基于ETag我最后一次见到。
I've gotten this to work for setting a constant header (it's just x-header: id
in this case), but I need something that varies per request, based on the ETag I last saw.
更新:
transformRequest
看起来前途无量,但我没有访问我发起的请求,或者这些数据的最终URL中的数据。至于我可以告诉我只能访问到身体我会过帐(未定义在我的情况,因为我正在做一个GET)和headersGetter功能。
transformRequest
looked promising, but I don't have access to the data that I initiated the request with, or the URL where that data ended up. As far as I can tell I only have access to the body I'd be POSTing (undefined in my case since I'm doing a GET) and the headersGetter function.
推荐答案
我发现,$资源处理其自身的ETag。
I discovered that $resource handles ETags on its own.
当我发布这个问题我还没有实现的东西服务器端。我设置了如果 - 无 - 匹配处理服务器端搞清楚我必须只使用$ HTTP服务的客户端上,但我现有的资源$电话。获得尝试过了,它处理建立如果 - 无 - 匹配我的资源的第一次轮询后自动报头。
I hadn't implemented the server side of things when I posted this question. I set up If-None-Match handling server side figuring I'd have to just use the $http service on the client, but tried it out with my existing $resource .get call and it handles setting up the If-None-Match header automatically after my first poll of the resource.
我重用1实例$资源设置过程中返回。我认为这是必需的自动处理的ETag
I am reusing the 1 instance that $resource returned during setup. I assume this is required for automatic ETag handling.
这篇关于发送的ETag与$资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!