fix(接口测试): head请求处理

--bug=1046993 --user=王旭 【接口测试】场景自定义请求-curl导入head请求-导入后请求方法为get https://www.tapd.cn/55049933/s/1585097
This commit is contained in:
WangXu10 2024-09-25 10:25:30 +08:00 committed by Craftsman
parent 2d76b1ad41
commit a02322ed43
3 changed files with 13 additions and 1 deletions

View File

@ -25,7 +25,8 @@ public interface CurlPatternConstants {
/**
* HTTP请求方法
*/
Pattern HTTP_METHOD_PATTERN = Pattern.compile("curl\\s+(?:[^\\s]+\\s+)*(-X|--request)\\s+'?(GET|POST|PUT|DELETE|PATCH|OPTIONS|HEAD|CONNECT)'?");
Pattern HTTP_METHOD_PATTERN = Pattern.compile("curl\\s+(?:[^\\s]+\\s+)*(-X|--request|--head)\\s+'?(GET|POST|PUT|DELETE|PATCH|OPTIONS|HEAD|CONNECT)'?");
Pattern HTTP_HEAD_METHOD_PATTERN = Pattern.compile("curl\\s+(?:[^\\s]+\\s+)*(--head|-I)\\s");
/**
* 默认HTTP请求方法

View File

@ -26,9 +26,12 @@ public class HttpMethodHandler extends CurlHandlerChain {
private CurlEntity.Method parseMethod(String curl) {
Matcher matcher = CurlPatternConstants.HTTP_METHOD_PATTERN.matcher(curl);
Matcher defaultMatcher = CurlPatternConstants.DEFAULT_HTTP_METHOD_PATTERN.matcher(curl);
Matcher headMatcher = CurlPatternConstants.HTTP_HEAD_METHOD_PATTERN.matcher(curl);
if (matcher.find()) {
String method = matcher.group(2);
return CurlEntity.Method.valueOf(method.toUpperCase());
} else if (headMatcher.find()) {
return CurlEntity.Method.HEAD;
} else if (defaultMatcher.find()) {
//如果命令中包含 -d --data没有明确请求方法默认为 POST
return CurlEntity.Method.POST;

View File

@ -959,6 +959,14 @@ public class ApiDebugControllerTests extends BaseTest {
" --insecure";
request.setCurl(curl);
this.requestPostWithOk(IMPORT_CURL, request);
curl = "curl -I https://example.com";
request.setCurl(curl);
this.requestPostWithOk(IMPORT_CURL, request);
curl = "curl --head https://example.com";
request.setCurl(curl);
this.requestPostWithOk(IMPORT_CURL, request);
}