Filter logged server responses

- Limit size to 1500 characters
- Remove collection names in /getSelectedCollection response
This commit is contained in:
Dan Stillman 2018-04-25 15:58:40 -04:00
parent 6cf11f083b
commit 6fb99d2d90
2 changed files with 38 additions and 9 deletions

View File

@ -1115,8 +1115,24 @@ Zotero.Server.Connector.GetSelectedCollection.prototype = {
Zotero.Prefs.clear('recentSaveTargets'); Zotero.Prefs.clear('recentSaveTargets');
} }
// TODO: Limit debug size sendResponseCallback(
sendResponseCallback(200, "application/json", JSON.stringify(response)); 200,
"application/json",
JSON.stringify(response),
{
// Filter out collection names in debug output
logFilter: function (str) {
try {
let json = JSON.parse(str.match(/^{"libraryID"[^]+/m)[0]);
json.targets.forEach(t => t.name = "\u2026");
return JSON.stringify(json);
}
catch (e) {
return str;
}
}
}
);
} }
} }

View File

@ -439,10 +439,12 @@ Zotero.Server.DataListener.prototype._processEndpoint = Zotero.Promise.coroutine
} }
// set up response callback // set up response callback
var me = this; var sendResponseCallback = function (code, contentType, arg, options) {
var sendResponseCallback = function(code, contentType, arg) { this._requestFinished(
me._requestFinished(me._generateResponse(code, contentType, arg)); this._generateResponse(code, contentType, arg),
} options
);
}.bind(this);
// Pass to endpoint // Pass to endpoint
// //
@ -512,7 +514,7 @@ Zotero.Server.DataListener.prototype._processEndpoint = Zotero.Promise.coroutine
/* /*
* returns HTTP data from a request * returns HTTP data from a request
*/ */
Zotero.Server.DataListener.prototype._requestFinished = function(response) { Zotero.Server.DataListener.prototype._requestFinished = function (response, options) {
if(this._responseSent) { if(this._responseSent) {
Zotero.debug("Request already finished; not sending another response"); Zotero.debug("Request already finished; not sending another response");
return; return;
@ -530,8 +532,19 @@ Zotero.Server.DataListener.prototype._requestFinished = function(response) {
try { try {
intlStream.init(this.oStream, "UTF-8", 1024, "?".charCodeAt(0)); intlStream.init(this.oStream, "UTF-8", 1024, "?".charCodeAt(0));
// write response // Filter logged response
Zotero.debug(response, 5); if (Zotero.Debug.enabled) {
let maxLogLength = 2000;
let str = response;
if (options && options.logFilter) {
str = options.logFilter(str);
}
if (str.length > maxLogLength) {
str = str.substr(0, maxLogLength) + `\u2026 (${response.length} chars)`;
}
Zotero.debug(str, 5);
}
intlStream.writeString(response); intlStream.writeString(response);
} finally { } finally {
intlStream.close(); intlStream.close();