使用角JS的$resource服务,是否有方法为资源的第2、3等轮询指定If- to匹配和ETag报头?
var SummarySearch = $resource(<<apiurl>>,
{ },
{
get: {
method: 'GET',
headers: {
'x-header': 'id'
}
}
});
我已经将它用于设置常量头(在本例中,它只是x-header: id
),但我需要根据我上次看到的ETag,每个请求都有不同的内容。
更新:
transformRequest
看起来很有希望,但我无法访问我发起请求的数据,也无法访问该数据的最终地址。据我所知,我只能访问身体,我将是POSTing (在我的情况下没有定义,因为我正在做GET)和headersGetter函数。
发布于 2014-07-28 21:23:58
我发现$resource自己处理ETags。
当我发布这个问题时,我还没有实现服务器端的功能。我设置了If-无匹配处理服务器端,认为我只需要在客户机上使用$http服务,但是使用我现有的$resource .get调用进行了尝试,并且在我对资源的第一次轮询之后,它自动处理设置If-无匹配标头。
我正在重用$resource在安装过程中返回的1实例。
编辑
我有真正的jQuery而不是jqLite。如果-没有匹配的话,似乎就是在那里。
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
if ( s.ifModified ) {
ifModifiedKey = ifModifiedKey || s.url;
if ( jQuery.lastModified[ ifModifiedKey ] ) {
jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ ifModifiedKey ] );
}
if ( jQuery.etag[ ifModifiedKey ] ) {
jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ ifModifiedKey ] );
}
}
https://stackoverflow.com/questions/24987957
复制相似问题