fix(接口测试): head请求处理
--bug=1046993 --user=王旭 【接口测试】场景自定义请求-curl导入head请求-导入后请求方法为get https://www.tapd.cn/55049933/s/1585097
This commit is contained in:
parent
2d76b1ad41
commit
a02322ed43
|
@ -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请求方法
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue