From 42f1293397b1ba97fb4fab37f2a46baea65b8a9d Mon Sep 17 00:00:00 2001 From: jy2156121 Date: Sat, 7 Mar 2020 11:53:34 +0800 Subject: [PATCH 1/3] =?UTF-8?q?Fixes=20#1321=20=E5=9C=A8=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E7=BD=91=E5=85=B3=E6=B5=81=E6=8E=A7=E8=A7=84=E5=88=99=E4=B8=AD?= =?UTF-8?q?=20=E5=8F=82=E6=95=B0=E5=B1=9E=E6=80=A7=E4=B8=AD=E7=9A=84Client?= =?UTF-8?q?=20IP=20=E5=92=8C=20Remote=20Host=E4=B8=8D=E8=83=BD=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=85=B7=E4=BD=93=E7=9A=84=E5=B1=9E=E6=80=A7=E5=80=BC?= =?UTF-8?q?=EF=BC=8CHearder=E3=80=81URL=E5=8F=82=E6=95=B0=E3=80=81Cookie?= =?UTF-8?q?=E4=B8=AD=E5=8F=AF=E4=BB=A5=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gateway/GatewayFlowRuleController.java | 27 +++++++++++++++++++ .../dialog/gateway/flow-rule-dialog.html | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/gateway/GatewayFlowRuleController.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/gateway/GatewayFlowRuleController.java index 0189163781..e5b22da772 100644 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/gateway/GatewayFlowRuleController.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/gateway/GatewayFlowRuleController.java @@ -158,6 +158,20 @@ public Result addFlowRule(@RequestBody AddFlowRuleReqVo r } itemEntity.setMatchStrategy(matchStrategy); } + + // 当参数属性为0-ClientIp 1-Host时,可以选择匹配 + }else if (Arrays.asList(PARAM_PARSE_STRATEGY_CLIENT_IP, PARAM_PARSE_STRATEGY_HOST).contains(parseStrategy)){ + String pattern = paramItem.getPattern(); + // 如果匹配串不为空,验证匹配模式 + if (StringUtil.isNotEmpty(pattern)) { + itemEntity.setPattern(pattern); + + Integer matchStrategy = paramItem.getMatchStrategy(); + if (!Arrays.asList(PARAM_MATCH_STRATEGY_EXACT, PARAM_MATCH_STRATEGY_CONTAINS, PARAM_MATCH_STRATEGY_REGEX).contains(matchStrategy)) { + return Result.ofFail(-1, "invalid matchStrategy: " + matchStrategy); + } + itemEntity.setMatchStrategy(matchStrategy); + } } } @@ -304,6 +318,19 @@ public Result updateFlowRule(@RequestBody UpdateFlowRuleR } itemEntity.setMatchStrategy(matchStrategy); } + // 当参数属性为0-ClientIp 1-Host时,可以选择匹配 + }else if (Arrays.asList(PARAM_PARSE_STRATEGY_CLIENT_IP, PARAM_PARSE_STRATEGY_HOST).contains(parseStrategy)){ + String pattern = paramItem.getPattern(); + // 如果匹配串不为空,验证匹配模式 + if (StringUtil.isNotEmpty(pattern)) { + itemEntity.setPattern(pattern); + + Integer matchStrategy = paramItem.getMatchStrategy(); + if (!Arrays.asList(PARAM_MATCH_STRATEGY_EXACT, PARAM_MATCH_STRATEGY_CONTAINS, PARAM_MATCH_STRATEGY_REGEX).contains(matchStrategy)) { + return Result.ofFail(-1, "invalid matchStrategy: " + matchStrategy); + } + itemEntity.setMatchStrategy(matchStrategy); + } } } else { entity.setParamItem(null); diff --git a/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/gateway/flow-rule-dialog.html b/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/gateway/flow-rule-dialog.html index 7dca16d719..ea744a7111 100644 --- a/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/gateway/flow-rule-dialog.html +++ b/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/gateway/flow-rule-dialog.html @@ -70,7 +70,7 @@ -
+