From d482c88ae36327f5687f2c69e8af1b7d7c9b38ad Mon Sep 17 00:00:00 2001 From: Andreas Tolfsen Date: Thu, 2 Jan 2020 13:08:54 +0000 Subject: [PATCH] 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 --- remote/Connection.jsm | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/remote/Connection.jsm b/remote/Connection.jsm index 9cc5ec990c07..4aa1abd0e2a3 100644 --- a/remote/Connection.jsm +++ b/remote/Connection.jsm @@ -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)); } /**