From f9eae5ce447fdf656f011bf513f1a40df75a7421 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Fri, 27 Aug 2021 18:20:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):=20#1?= =?UTF-8?q?006253=20=E5=85=A8=E5=B1=80=E8=AF=B7=E6=B1=82=E5=A4=B4=E4=B8=8E?= =?UTF-8?q?=E5=B1=80=E9=83=A8=E8=AF=B7=E6=B1=82=E5=A4=B4=E5=8E=BB=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【全局请求头与局部请求头去重】https://www.tapd.cn/55049933/bugtrace/bugs/view?bug_id=1155049933001006253 --- .../request/sampler/MsHTTPSamplerProxy.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index 4f7226b702..2745ed41ee 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -650,7 +650,22 @@ public class MsHTTPSamplerProxy extends MsTestElement { // header 也支持 mock 参数 List keyValues = headers.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).collect(Collectors.toList()); for (KeyValue keyValue : keyValues) { - headerManager.add(new Header(keyValue.getName(), ScriptEngineUtils.buildFunctionCallString(keyValue.getValue()))); + boolean hasHead = false; + //检查是否已经有重名的Head。如果Header重复会导致执行报错 + if(headerManager.getHeaders() != null){ + for(int i = 0; i < headerManager.getHeaders().size(); i ++){ + Header header = headerManager.getHeader(i); + String headName = header.getName(); + if(StringUtils.equals(headName,keyValue.getName())){ + hasHead = true; + break; + } + } + } + + if(!hasHead){ + headerManager.add(new Header(keyValue.getName(), ScriptEngineUtils.buildFunctionCallString(keyValue.getValue()))); + } } if (headerManager.getHeaders().size() > 0 && isAdd) { tree.add(headerManager);