From 0d9d396fa0a79995e2eb421bc44080e88079940f Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Wed, 25 Sep 2024 11:29:30 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20curl=E5=A2=9E=E5=8A=A0raw=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/curl/constants/CurlPatternConstants.java | 3 ++- .../io/metersphere/api/curl/handler/HttpBodyHandler.java | 8 +++++++- frontend/src/views/api-test/components/utils.ts | 7 +++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/curl/constants/CurlPatternConstants.java b/backend/services/api-test/src/main/java/io/metersphere/api/curl/constants/CurlPatternConstants.java index bcaf1160a4..ec14e45842 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/curl/constants/CurlPatternConstants.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/curl/constants/CurlPatternConstants.java @@ -52,7 +52,8 @@ public interface CurlPatternConstants { /** * --data-raw 请求体 */ - Pattern HTTP_ROW_BODY_PATTERN = Pattern.compile("--data-raw '(.+?)'(?s)", Pattern.DOTALL); + Pattern HTTP_XML_JSON_BODY_PATTERN = Pattern.compile("--data-raw '(.+?)'(?s)", Pattern.DOTALL); + Pattern HTTP_ROW_BODY_PATTERN = Pattern.compile("--data-binary\\s+['\"](.+?)['\"](?s)", Pattern.DOTALL); /** * --form 请求体 diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/curl/handler/HttpBodyHandler.java b/backend/services/api-test/src/main/java/io/metersphere/api/curl/handler/HttpBodyHandler.java index f76f654f40..2508d77315 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/curl/handler/HttpBodyHandler.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/curl/handler/HttpBodyHandler.java @@ -50,9 +50,15 @@ public class HttpBodyHandler extends CurlHandlerChain { entity.setBody(parseUrlEncodeBody(urlencodeMatcher)); } + Matcher xmlJsonMatcher = CurlPatternConstants.HTTP_XML_JSON_BODY_PATTERN.matcher(curl); + if (xmlJsonMatcher.find()) { + entity.setBody(parseRowBody(xmlJsonMatcher, entity)); + } + Matcher rawMatcher = CurlPatternConstants.HTTP_ROW_BODY_PATTERN.matcher(curl); if (rawMatcher.find()) { - entity.setBody(parseRowBody(rawMatcher, entity)); + entity.setBodyType(Body.BodyType.RAW.name()); + entity.setBody(rawMatcher.group(1)); } Matcher defaultMatcher = CurlPatternConstants.DEFAULT_HTTP_BODY_PATTERN.matcher(curl); diff --git a/frontend/src/views/api-test/components/utils.ts b/frontend/src/views/api-test/components/utils.ts index 9549b30401..89d93e3105 100644 --- a/frontend/src/views/api-test/components/utils.ts +++ b/frontend/src/views/api-test/components/utils.ts @@ -298,6 +298,13 @@ export function parseCurlBody(bodyType: RequestBodyFormat, body: Record