зеркало из https://github.com/mozilla/gecko-dev.git
Bug 776778 - Implement X-If-Unmodified-Since on GET method; r=rnewman
This reflects changes to the spec in bug 776768.
This commit is contained in:
Родитель
bef2e10280
Коммит
a690d968af
|
@ -132,13 +132,25 @@ ServerBSO.prototype = {
|
|||
}
|
||||
|
||||
if (request.hasHeader("x-if-modified-since")) {
|
||||
let headerModified = parseInt(request.getHeader("x-if-modified-since"));
|
||||
let headerModified = parseInt(request.getHeader("x-if-modified-since"),
|
||||
10);
|
||||
CommonUtils.ensureMillisecondsTimestamp(headerModified);
|
||||
|
||||
if (headerModified >= this.modified) {
|
||||
code = 304;
|
||||
status = "Not Modified";
|
||||
|
||||
sendResponse();
|
||||
return;
|
||||
}
|
||||
} else if (request.hasHeader("x-if-unmodified-since")) {
|
||||
let requestModified = parseInt(request.getHeader("x-if-unmodified-since"),
|
||||
10);
|
||||
let serverModified = this.modified;
|
||||
|
||||
if (serverModified > requestModified) {
|
||||
code = 412;
|
||||
status = "Precondition Failed";
|
||||
sendResponse();
|
||||
return;
|
||||
}
|
||||
|
@ -652,6 +664,16 @@ StorageServerCollection.prototype = {
|
|||
response.setStatusLine(request.httpVersion, 304, "Not Modified");
|
||||
return;
|
||||
}
|
||||
} else if (request.hasHeader("x-if-unmodified-since")) {
|
||||
let requestModified = parseInt(request.getHeader("x-if-unmodified-since"),
|
||||
10);
|
||||
let serverModified = this.timestamp;
|
||||
|
||||
if (serverModified > requestModified) {
|
||||
response.setHeader("X-Last-Modified", "" + serverModified);
|
||||
response.setStatusLine(request.httpVersion, 412, "Precondition Failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.full) {
|
||||
|
|
|
@ -464,6 +464,60 @@ add_test(function test_bso_delete_unmodified() {
|
|||
server.stop(run_next_test);
|
||||
});
|
||||
|
||||
add_test(function test_collection_get_unmodified_since() {
|
||||
_("Ensure conditional unmodified get on collection works when it should.");
|
||||
|
||||
let server = new StorageServer();
|
||||
server.registerUser("123", "password");
|
||||
server.startSynchronous(PORT);
|
||||
let collection = server.user("123").createCollection("testcoll");
|
||||
collection.insert("bso0", {foo: "bar"});
|
||||
|
||||
let serverModified = collection.timestamp;
|
||||
|
||||
let request1 = localRequest("/2.0/123/storage/testcoll", "123", "password");
|
||||
request1.setHeader("X-If-Unmodified-Since", serverModified);
|
||||
let error = doGetRequest(request1);
|
||||
do_check_null(error);
|
||||
do_check_eq(request1.response.status, 200);
|
||||
|
||||
let request2 = localRequest("/2.0/123/storage/testcoll", "123", "password");
|
||||
request2.setHeader("X-If-Unmodified-Since", serverModified - 1);
|
||||
let error = doGetRequest(request2);
|
||||
do_check_null(error);
|
||||
do_check_eq(request2.response.status, 412);
|
||||
|
||||
server.stop(run_next_test);
|
||||
});
|
||||
|
||||
add_test(function test_bso_get_unmodified_since() {
|
||||
_("Ensure conditional unmodified get on BSO works appropriately.");
|
||||
|
||||
let server = new StorageServer();
|
||||
server.registerUser("123", "password");
|
||||
server.startSynchronous(PORT);
|
||||
let collection = server.user("123").createCollection("testcoll");
|
||||
collection.insert("bso0", {foo: "bar"});
|
||||
|
||||
let serverModified = collection.timestamp;
|
||||
|
||||
let request1 = localRequest("/2.0/123/storage/testcoll/bso0", "123",
|
||||
"password");
|
||||
request1.setHeader("X-If-Unmodified-Since", serverModified);
|
||||
let error = doGetRequest(request1);
|
||||
do_check_null(error);
|
||||
do_check_eq(request1.response.status, 200);
|
||||
|
||||
let request2 = localRequest("/2.0/123/storage/testcoll/bso0", "123",
|
||||
"password");
|
||||
request2.setHeader("X-If-Unmodified-Since", serverModified - 1);
|
||||
let error = doGetRequest(request2);
|
||||
do_check_null(error);
|
||||
do_check_eq(request2.response.status, 412);
|
||||
|
||||
server.stop(run_next_test);
|
||||
});
|
||||
|
||||
add_test(function test_missing_collection_404() {
|
||||
_("Ensure a missing collection returns a 404.");
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче