зеркало из https://github.com/mozilla/gecko-dev.git
Bug 673548 - Part 5: include X-Weave-Records header in ServerCollection GET responses. r=philikon
* * * Bug 673548 - Part 6: test for X-Weave-Records header. r=philikon
This commit is contained in:
Родитель
b332ca13a0
Коммит
d8d9c38915
|
@ -304,8 +304,11 @@ ServerCollection.prototype = {
|
|||
if (options.limit) {
|
||||
data = data.slice(0, options.limit);
|
||||
}
|
||||
// Our implementation of application/newlines
|
||||
// Our implementation of application/newlines.
|
||||
result = data.join("\n") + "\n";
|
||||
|
||||
// Use options as a backchannel to report count.
|
||||
options.recordCount = data.length;
|
||||
} else {
|
||||
let data = [id for ([id, wbo] in Iterator(this._wbos))
|
||||
if (this._inResultSet(wbo, options))];
|
||||
|
@ -313,6 +316,7 @@ ServerCollection.prototype = {
|
|||
data = data.slice(0, options.limit);
|
||||
}
|
||||
result = JSON.stringify(data);
|
||||
options.recordCount = data.length;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
@ -393,6 +397,14 @@ ServerCollection.prototype = {
|
|||
switch(request.method) {
|
||||
case "GET":
|
||||
body = self.get(options);
|
||||
// "If supported by the db, this header will return the number of
|
||||
// records total in the request body of any multiple-record GET
|
||||
// request."
|
||||
let records = options.recordCount;
|
||||
self._log.info("Records: " + records);
|
||||
if (records != null) {
|
||||
response.setHeader("X-Weave-Records", "" + records);
|
||||
}
|
||||
break;
|
||||
|
||||
case "POST":
|
||||
|
|
|
@ -153,3 +153,26 @@ add_test(function test_storage_request() {
|
|||
);
|
||||
});
|
||||
});
|
||||
|
||||
add_test(function test_x_weave_records() {
|
||||
let s = new SyncServer();
|
||||
s.registerUser("john", "password");
|
||||
|
||||
s.createContents("john", {
|
||||
crypto: {foos: {foo: "bar"},
|
||||
bars: {foo: "baz"}}
|
||||
});
|
||||
s.start(8080, function () {
|
||||
let wbo = localRequest("/1.1/john/storage/crypto/foos");
|
||||
wbo.get(function (err) {
|
||||
// WBO fetches don't have one.
|
||||
do_check_false("x-weave-records" in this.response.headers);
|
||||
let col = localRequest("/1.1/john/storage/crypto");
|
||||
col.get(function (err) {
|
||||
// Collection fetches do.
|
||||
do_check_eq(this.response.headers["x-weave-records"], "2");
|
||||
s.stop(run_next_test);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче