Use canonicalJson

This commit is contained in:
Mitra Ardron
2018-09-15 17:28:18 +10:00
parent 49113f78e2
commit 596a7a360b
6 changed files with 16 additions and 10 deletions

View File

@ -4,6 +4,7 @@ const httptools = require('./httptools'); // Expose some of the httptools so tha
const Url = require('url');
const stream = require('readable-stream');
const debughttp = require('debug')('dweb-transports:http');
const stringify = require('canonical-json');
defaulthttpoptions = {
@ -129,7 +130,7 @@ class TransportHTTP extends Transport {
p_rawadd(url, sig) {
// Logged by Transports
if (!url || !sig) throw new errors.CodingError("TransportHTTP.p_rawadd: invalid parms", url, sig);
let value = JSON.stringify(sig.preflight(Object.assign({},sig)))+"\n";
let value = stringify(sig.preflight(Object.assign({},sig)))+"\n";
return httptools.p_POST(this._url(url, servercommands.rawadd), "application/json", value); // Returns immediately
}
@ -258,10 +259,10 @@ class TransportHTTP extends Transport {
// Logged by Transports
//debughttp("p_set %o %o %o", url, keyvalues, value);
if (typeof keyvalues === "string") {
let kv = JSON.stringify([{key: keyvalues, value: value}]);
let kv = stringify([{key: keyvalues, value: value}]);
await httptools.p_POST(this._url(url, servercommands.set), "application/json", kv); // Returns immediately
} else {
let kv = JSON.stringify(Object.keys(keyvalues).map((k) => ({"key": k, "value": keyvalues[k]})));
let kv = stringify(Object.keys(keyvalues).map((k) => ({"key": k, "value": keyvalues[k]})));
await httptools.p_POST(this._url(url, servercommands.set), "application/json", kv); // Returns immediately
}
}