Add etag and if-modified-since support. (http request)

The execMethod() returns a third parameter which is the http response.
(In order to get the date and the etag header values)
This commit is contained in:
oeuillot
2016-03-14 17:43:30 +01:00
parent 5c7a378164
commit a8733f5c4c

View File

@@ -40,8 +40,8 @@ MovieDB.prototype.requestToken = function(fn){
if(err) {
fn(err);
} else {
self.token = res.body;
fn();
self.token = res.body;
fn();
}
});
@@ -85,6 +85,17 @@ var execMethod = function(type, params, endpoint, fn){
var req = request(type, endpoints.base_url + endpoint)
.query({api_key : this.api_key})
.set('Accept', 'application/json');
if (params.ifNoneMatch) {
req=req.set('If-None-Match', params.ifNoneMatch);
} else if (params.ifModifiedSince) {
var t=params.ifModifiedSince;
if (t.toUTCString) {
t=t.toUTCString();
}
req=req.set('If-Modified-Since', t);
}
if(type === 'GET')
req.query(params);
@@ -93,9 +104,9 @@ var execMethod = function(type, params, endpoint, fn){
req.end(function(err, res){
if(err){
fn(err);
fn(err, null, res);
} else {
fn(null, res.body);
fn(null, res.body, res);
}
});
};