diff --git a/server/core/resource.cc b/server/core/resource.cc index de3e69771..ca4722ea4 100644 --- a/server/core/resource.cc +++ b/server/core/resource.cc @@ -42,6 +42,20 @@ using std::stringstream; using mxs::SpinLock; using mxs::SpinLockGuard; +static bool drop_path_part(std::string& path) +{ + size_t pos = path.find_last_of('/'); + bool rval = false; + + if (pos != std::string::npos) + { + path.erase(pos); + rval = true; + } + + return rval && path.length(); +} + /** * Class that keeps track of resource modification times */ @@ -54,21 +68,27 @@ public: { } - void modify(const string& path) + void modify(const std::string& orig_path) { - map::iterator it = m_etag.find(path); + std::string path = orig_path; - if (it != m_etag.end()) + do { - it->second++; - } - else - { - // First modification - m_etag[path] = 1; - } + map::iterator it = m_etag.find(path); - m_last_modified[path] = time(NULL); + if (it != m_etag.end()) + { + it->second++; + } + else + { + // First modification + m_etag[path] = 1; + } + + m_last_modified[path] = time(NULL); + } + while (drop_path_part(path)); } time_t last_modified(const string& path) const diff --git a/server/core/test/rest-api/test/http.js b/server/core/test/rest-api/test/http.js index 9a0104a9a..452ca4c66 100644 --- a/server/core/test/rest-api/test/http.js +++ b/server/core/test/rest-api/test/http.js @@ -18,6 +18,12 @@ describe("HTTP Headers", function() { .then(function(resp) { resp.headers.etag.should.be.equal("\"1\"") }) + .then(function() { + return request.get(base_url + "/servers", {resolveWithFullResponse: true}) + }) + .then(function(resp) { + resp.headers.etag.should.be.equal("\"1\"") + }) }); it("Last-Modified changes after modification", function(done) { @@ -46,6 +52,13 @@ describe("HTTP Headers", function() { .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) + }) + .then(function() { + return request.get(base_url + "/servers", {resolveWithFullResponse: true}) + }) .then(function(resp) { resp.headers["last-modified"].should.not.be.null resp.headers["last-modified"].should.not.be.equal(date)