Skip to content

Commit

Permalink
fix(apiTest): test result return file but show text
Browse files Browse the repository at this point in the history
  • Loading branch information
scarqin committed Sep 13, 2022
1 parent a308c50 commit 2d737e5
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/workbench/node/request/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,18 @@ const { resolve } = require('path');
tmpReportData.response.responseLength = tmpInputResponseObj.chunk.length;
let tmpDetected = {},
tmpSuffix = _LibsMineType.getSuffix(inputRes.headers['content-type']),
tmpFileBinary;
tmpFileBinary,
blobFileName;
try {
blobFileName = _ContentDisposition.parse(inputRes.headers['content-disposition'] || 'undefined')
.parameters.filename;
} catch (PARSE_CONTENT_DISPOSITION_ERR) {
try {
blobFileName = _ContentDisposition.parse(
encodeURI(inputRes.headers['content-disposition'] || 'undefined').replace(/\?/g, '')
).parameters.filename;
} catch (URL_ENCODE_PARSE_CONTENT_DISPOSITION_ERR) {}
}
if (!inputRes.headers['content-type']) {
tmpDetected =
_GetFileClass.byContent(
Expand All @@ -423,10 +434,11 @@ const { resolve } = require('path');
) || {};
}
if (
/^(text\/(.*))|(application(.*)((\/)|(\+))json)|(application(.*)((\/)|(\+))xml)/gi.test(
!blobFileName &&
(/^(text\/(.*))|(application(.*)((\/)|(\+))json)|(application(.*)((\/)|(\+))xml)/gi.test(
inputRes.headers['content-type']
) ||
(!(inputRes.headers['content-type'] && tmpSuffix) && !(tmpDetected && tmpDetected.mime))
(!(inputRes.headers['content-type'] && tmpSuffix) && !(tmpDetected && tmpDetected.mime)))
) {
tmpReportData.response.contentType = inputRes.headers['content-type'];
if (tmpReportData.response.responseLength >= 300 * 1024) {
Expand All @@ -449,17 +461,7 @@ const { resolve } = require('path');
tmpReportData.response.responseType = 'stream';
tmpReportData.response.contentType = inputRes.headers['content-type'] || tmpDetected.mime;
let tmpPathUrl = inputTestData.options.path;
try {
tmpReportData.blobFileName = _ContentDisposition.parse(
inputRes.headers['content-disposition'] || 'undefined'
).parameters.filename;
} catch (PARSE_CONTENT_DISPOSITION_ERR) {
try {
tmpReportData.blobFileName = _ContentDisposition.parse(
encodeURI(inputRes.headers['content-disposition'] || 'undefined').replace(/\?/g, '')
).parameters.filename;
} catch (URL_ENCODE_PARSE_CONTENT_DISPOSITION_ERR) {}
}
tmpReportData.blobFileName = blobFileName;
if (!tmpReportData.blobFileName && tmpDetected && tmpDetected.ext) {
tmpReportData.blobFileName = `response.${tmpDetected.ext}`;
} else if (!tmpReportData.blobFileName) {
Expand Down

0 comments on commit 2d737e5

Please sign in to comment.