add test cases for compressed response

This commit is contained in:
guox191
2019-03-21 18:18:20 +08:00
parent a8c9f590fc
commit c040ae4578
4 changed files with 52 additions and 20 deletions

View File

@@ -242,18 +242,16 @@ class Recorder extends events.EventEmitter {
bodyContent = iconv.decode(bodyContent, currentCharset);
}
result.mime = contentType;
result.content = bodyContent.toString();
result.type = contentType && /application\/json/i.test(contentType) ? 'json' : 'text';
} else if (contentType && /image/i.test(contentType)) {
result.type = 'image';
result.mime = contentType;
result.content = bodyContent;
} else {
result.type = contentType;
result.mime = contentType;
result.content = bodyContent.toString();
}
result.mime = contentType;
result.fileName = path.basename(record.path);
result.statusCode = record.statusCode;
} catch (e) {

View File

@@ -146,10 +146,8 @@ class webInterface extends events.EventEmitter {
if (err || !result) {
res.json({});
} else if (result.statusCode === 200 && result.mime) {
if (result.type === 'json' ||
result.mime.indexOf('text') === 0 ||
// deal with 'application/x-javascript' and 'application/javascript'
result.mime.indexOf('javascript') > -1) {
// deal with 'application/x-javascript' and 'application/javascript'
if (/json|text|javascript/.test(result.mime)) {
_resContent();
} else if (result.type === 'image') {
_resDownload(false);