refactor(接口测试): curl增加raw类型

This commit is contained in:
WangXu10 2024-09-25 11:29:30 +08:00 committed by 刘瑞斌
parent 95ea080fe8
commit 0d9d396fa0
3 changed files with 16 additions and 2 deletions

View File

@ -52,7 +52,8 @@ public interface CurlPatternConstants {
/** /**
* --data-raw 请求体 * --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 请求体 * --form 请求体

View File

@ -50,9 +50,15 @@ public class HttpBodyHandler extends CurlHandlerChain {
entity.setBody(parseUrlEncodeBody(urlencodeMatcher)); 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); Matcher rawMatcher = CurlPatternConstants.HTTP_ROW_BODY_PATTERN.matcher(curl);
if (rawMatcher.find()) { 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); Matcher defaultMatcher = CurlPatternConstants.DEFAULT_HTTP_BODY_PATTERN.matcher(curl);

View File

@ -298,6 +298,13 @@ export function parseCurlBody(bodyType: RequestBodyFormat, body: Record<string,
value: body as string, value: body as string,
}; };
break; break;
case RequestBodyFormat.RAW:
requestBody.bodyType = bodyType;
requestBody.rawBody = {
...cloneDeep(defaultBodyParams.rawBody),
value: body as string,
};
break;
case RequestBodyFormat.FORM_DATA: case RequestBodyFormat.FORM_DATA:
requestBody.bodyType = bodyType; requestBody.bodyType = bodyType;
requestBody.formDataBody = { requestBody.formDataBody = {