bug 1606612: remote: pretty-print WebSocket JSON payloads when verbose logging r=remote-protocol-reviewers,whimboo

When remote.log.level is Log.Level.Info or above, verbose logging
is enabled and we pretty-print JSON payloads in requests to the
HTTPD in JSONHandler.

This patch matches the behaviour with JSON payloads being transmitted
across WebSocket connections.

Differential Revision: https://phabricator.services.mozilla.com/D58506

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andreas Tolfsen 2020-01-02 13:08:54 +00:00
Родитель 4f915f8ab5
Коммит d482c88ae3
1 изменённых файлов: 10 добавлений и 4 удалений

Просмотреть файл

@ -6,14 +6,15 @@
var EXPORTED_SYMBOLS = ["Connection"];
const { Log } = ChromeUtils.import("chrome://remote/content/Log.jsm");
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
const { Log } = ChromeUtils.import("chrome://remote/content/Log.jsm");
const { UnknownMethodError } = ChromeUtils.import(
"chrome://remote/content/Error.jsm"
);
const { Protocol } = ChromeUtils.import("chrome://remote/content/Protocol.jsm");
XPCOMUtils.defineLazyGetter(this, "log", Log.get);
XPCOMUtils.defineLazyServiceGetter(
@ -61,9 +62,14 @@ class Connection {
this.sessions.set(session.id, session);
}
send(message) {
log.trace(`<-(connection ${this.id}) ${JSON.stringify(message)}`);
this.transport.send(message);
send(body) {
const payload = JSON.stringify(
body,
Protocol.sanitize,
Log.verbose ? "\t" : undefined
);
log.trace(`<-(connection ${this.id}) ${payload}`);
this.transport.send(JSON.parse(payload));
}
/**