From 33ebc1e065a67d2d8fdf3863bb7f1f930d8d85e3 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Thu, 5 Nov 2020 17:16:30 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E9=80=89=E6=8B=A9mutipart/from-data=E5=90=8E,=E6=B8=85?= =?UTF-8?q?=E9=99=A4=E5=85=B6=E4=BB=96content-type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/test/model/ScenarioModel.js | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/frontend/src/business/components/api/test/model/ScenarioModel.js b/frontend/src/business/components/api/test/model/ScenarioModel.js index 08060379fb..f13525ea02 100644 --- a/frontend/src/business/components/api/test/model/ScenarioModel.js +++ b/frontend/src/business/components/api/test/model/ScenarioModel.js @@ -1198,16 +1198,25 @@ class JMXGenerator { } addEnvironments(environments, target) { - let keys = new Set(); + let targetMap = new Map(); target.forEach(item => { - keys.add(item.name); + if (item.name) { + targetMap.set(item.name, item.enable); + } }); let envArray = environments; if (!(envArray instanceof Array)) { envArray = JSON.parse(environments); } envArray.forEach(item => { - if (item.enable != false && item.name && !keys.has(item.name)) { + let targetItem = targetMap.get(item.name); + let hasItem = undefined; + if (targetItem) { + hasItem = (targetItem.enable === false ? false : true); + } else { + hasItem = false; + } + if (item.enable != false && item.name && !hasItem) { target.push(new KeyValue({name: item.name, value: item.value})); } }) @@ -1311,7 +1320,10 @@ class JMXGenerator { if (!(scenario.environment.config instanceof Object)) { config = JSON.parse(scenario.environment.config); } - this.addEnvironments(config.httpConfig.headers, request.headers) + this.addEnvironments(config.httpConfig.headers, request.headers); + if (request.doMultipartPost) { + this.removeContentType(request); + } } let name = request.name + " Headers"; this.addBodyFormat(request); @@ -1403,6 +1415,17 @@ class JMXGenerator { } } + removeContentType(request) { + for (let index in request.headers) { + if (request.headers.hasOwnProperty(index)) { + if (request.headers[index].name === 'Content-Type' && request.headers[index].enable != false) { + request.headers.splice(index, 1); + break; + } + } + } + } + addRequestArguments(httpSamplerProxy, request) { let args = this.filterKV(request.parameters); if (args.length > 0) {