[console] Set multiline json content type to application/x-ndjson (#10223)

Backports PR #10201

**Commit 1:**
[console] Set multiline json content type to application/x-ndjson

* Original sha: 8a703d868e
* Authored by Jonathan Budzenski <jon@jbudz.me> on 2017-02-06T18:22:03Z
This commit is contained in:
jasper 2017-02-07 10:12:31 -05:00 committed by Court Ewing
parent 4d1e3129fb
commit 94a4a8a2d0

View file

@ -23,8 +23,17 @@ module.exports.send = function (method, path, data, server, disable_auth_alert)
try {
JSON.parse(data);
contentType = 'application/json';
} catch (e) {
contentType = 'text/plain';
}
catch (e) {
try {
data.split('\n').forEach(line => {
if (!line) return;
JSON.parse(line);
});
contentType = 'application/x-ndjson';
} catch (e){
contentType = 'text/plain';
}
}
}