MXS-1220: Add Last-Modified and ETag headers

The resource system now tracks both the time when a resource was last
modified and the revision number of the resource. This allows working
Last-Modified and ETag headers to be generated by the REST API.

The If-Modified-Since and If-None-Match request headers are not yet
processed and using them will always return the resource instead of a 304
Not Modified response.
This commit is contained in:
Markus Mäkelä
2017-05-07 23:32:18 +03:00
parent 717f883839
commit 3deb497394
4 changed files with 170 additions and 7 deletions

View File

@ -0,0 +1,59 @@
require("../utils.js")()
describe("HTTP Headers", function() {
before(startMaxScale)
it("ETag changes after modification", function() {
return request.get(base_url + "/servers/server1", {resolveWithFullResponse: true})
.then(function(resp) {
resp.headers.etag.should.be.equal("0")
var srv = JSON.parse(resp.body)
delete srv.data.relationships
return request.put(base_url + "/servers/server1", {json: srv})
})
.then(function() {
return request.get(base_url + "/servers/server1", {resolveWithFullResponse: true})
})
.then(function(resp) {
resp.headers.etag.should.be.equal("1")
})
});
it("Last-Modified changes after modification", function() {
var date;
return request.get(base_url + "/servers/server1", {resolveWithFullResponse: true})
.then(function(resp) {
// Store the current modification time
resp.headers["last-modified"].should.not.be.null
date = resp.headers["last-modified"]
// Modify resource after three seconds
setTimeout(function() {
var srv = JSON.parse(resp.body)
srv.data.relationships = {
services: {
data: [
{id: "RW-Split-Router", type: "services"}
]
}
}
request.put(base_url + "/servers/server1", {json: srv})
.then(function() {
return request.get(base_url + "/servers/server1", {resolveWithFullResponse: true})
})
.then(function(resp) {
resp.headers["last-modified"].should.not.be.null
resp.headers["last-modified"].should.not.be.equal(date)
})
}, 3000)
})
});
after(stopMaxScale)
});