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 2102dbf7cf..bcaf1160a4 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 @@ -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请求方法 diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/curl/handler/HttpMethodHandler.java b/backend/services/api-test/src/main/java/io/metersphere/api/curl/handler/HttpMethodHandler.java index c994e69b9b..dc479ea1c1 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/curl/handler/HttpMethodHandler.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/curl/handler/HttpMethodHandler.java @@ -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; diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugControllerTests.java index abaeaa1385..3358ad0208 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugControllerTests.java @@ -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); }