mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 769816 - Send newline-delimited requests instead of JSON; r=rnewman
This commit is contained in:
parent
38c01fb834
commit
b316b317fd
@ -1084,7 +1084,8 @@ StorageCollectionGetRequest.prototype = {
|
||||
function StorageCollectionSetRequest() {
|
||||
StorageServiceRequest.call(this);
|
||||
|
||||
this._inputBSOs = [];
|
||||
this._lines = [];
|
||||
this._size = 0;
|
||||
|
||||
this.successfulIDs = new Set();
|
||||
this.failures = new Map();
|
||||
@ -1092,6 +1093,16 @@ function StorageCollectionSetRequest() {
|
||||
StorageCollectionSetRequest.prototype = {
|
||||
__proto__: StorageServiceRequest.prototype,
|
||||
|
||||
/**
|
||||
* Add a BasicStorageObject to this request.
|
||||
*
|
||||
* Please note that the BSO content is retrieved when the BSO is added to
|
||||
* the request. If the BSO changes after it is added to a request, those
|
||||
* changes will not be reflected in the request.
|
||||
*
|
||||
* @param bso
|
||||
* (BasicStorageObject) BSO to add to the request.
|
||||
*/
|
||||
addBSO: function addBSO(bso) {
|
||||
if (!bso instanceof BasicStorageObject) {
|
||||
throw new Error("argument must be a BasicStorageObject instance.");
|
||||
@ -1101,11 +1112,15 @@ StorageCollectionSetRequest.prototype = {
|
||||
throw new Error("Passed BSO must have id defined.");
|
||||
}
|
||||
|
||||
this._inputBSOs.push(bso);
|
||||
let line = JSON.stringify(bso).replace("\n", "\u000a");
|
||||
|
||||
// This is off by 1 in the larger direction. We don't care.
|
||||
this._size += line.length + "\n".length;
|
||||
this._lines.push(line);
|
||||
},
|
||||
|
||||
_onDispatch: function _onDispatch() {
|
||||
this._data = JSON.stringify(this._inputBSOs);
|
||||
this._data = this._lines.join("\n");
|
||||
},
|
||||
|
||||
_completeParser: function _completeParser(response) {
|
||||
@ -1612,7 +1627,7 @@ StorageServiceClient.prototype = {
|
||||
let uri = this._baseURI + "storage/" + collection;
|
||||
let request = this._getRequest(uri, "POST", {
|
||||
requestType: StorageCollectionSetRequest,
|
||||
contentType: "application/json",
|
||||
contentType: "application/newlines",
|
||||
accept: "application/json",
|
||||
allowIfUnmodified: true,
|
||||
});
|
||||
|
@ -683,6 +683,34 @@ add_test(function test_set_bsos_invalid_bso() {
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_set_bsos_newline() {
|
||||
_("Ensure that newlines in BSO payloads are formatted properly.");
|
||||
|
||||
let [server, client, username] = getServerAndClient();
|
||||
let user = server.user(username);
|
||||
|
||||
let request = client.setBSOs("testcoll");
|
||||
|
||||
let bso0 = new BasicStorageObject("bso0");
|
||||
bso0.payload = "hello\nworld";
|
||||
request.addBSO(bso0);
|
||||
|
||||
let bso1 = new BasicStorageObject("bso1");
|
||||
bso1.payload = "foobar";
|
||||
request.addBSO(bso1);
|
||||
|
||||
request.dispatch(function onComplete(error, request) {
|
||||
do_check_null(error);
|
||||
do_check_eq(request.successfulIDs.size(), 2);
|
||||
|
||||
let coll = user.collection("testcoll");
|
||||
do_check_eq(coll.bso("bso0").payload, bso0.payload);
|
||||
do_check_eq(coll.bso("bso1").payload, bso1.payload);
|
||||
|
||||
server.stop(run_next_test);
|
||||
});
|
||||
});
|
||||
|
||||
add_test(function test_delete_bso_simple() {
|
||||
_("Ensure deletion of individual BSOs works.");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user