From 08b973c03e3b41c5609b6c64d9128427a85c27db Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Wed, 14 Oct 2020 10:55:52 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20POST=20=E6=94=AF=E6=8C=81=20multipart/form-data?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/dto/scenario/request/HttpRequest.java | 2 + .../controller/TestController.java | 9 ++++ backend/src/main/java/io/metersphere/xpack | 2 +- .../components/request/ApiHttpRequestForm.vue | 48 +++++++++++-------- .../business/components/api/test/model/JMX.js | 1 + .../api/test/model/ScenarioModel.js | 3 +- frontend/src/business/components/xpack | 2 +- frontend/src/i18n/en-US.js | 1 + frontend/src/i18n/zh-CN.js | 1 + frontend/src/i18n/zh-TW.js | 1 + 10 files changed, 46 insertions(+), 24 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/scenario/request/HttpRequest.java b/backend/src/main/java/io/metersphere/api/dto/scenario/request/HttpRequest.java index f43fcc41c7..74b497d07c 100644 --- a/backend/src/main/java/io/metersphere/api/dto/scenario/request/HttpRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/scenario/request/HttpRequest.java @@ -35,4 +35,6 @@ public class HttpRequest extends Request { private Long responseTimeout; @JSONField(ordinal = 16) private Boolean followRedirects; + @JSONField(ordinal = 17) + private Boolean doMultipartPost; } diff --git a/backend/src/main/java/io/metersphere/controller/TestController.java b/backend/src/main/java/io/metersphere/controller/TestController.java index c3b7c033af..9783d98572 100644 --- a/backend/src/main/java/io/metersphere/controller/TestController.java +++ b/backend/src/main/java/io/metersphere/controller/TestController.java @@ -25,6 +25,15 @@ public class TestController { return jsonObject; } + @PostMapping(value = "/multipart", consumes = {"multipart/form-data"}) + public Object testMultipart(@RequestPart(value = "id") String id, @RequestPart(value = "user") User user, @RequestParam(value = "name") String name) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", id); + jsonObject.put("user", user.getName()); + jsonObject.put("name", name); + return jsonObject; + } + @GetMapping(value = "/{str}") public Object getString(@PathVariable String str) throws InterruptedException { if (StringUtils.equals("error", str)) { diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index ee74568be0..cf6b065263 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit ee74568be0beba46da19616f5832e83f9164c688 +Subproject commit cf6b06526324326a563d933e07118fac014a63b4 diff --git a/frontend/src/business/components/api/test/components/request/ApiHttpRequestForm.vue b/frontend/src/business/components/api/test/components/request/ApiHttpRequestForm.vue index 4999ba3842..3e0e43b21a 100644 --- a/frontend/src/business/components/api/test/components/request/ApiHttpRequestForm.vue +++ b/frontend/src/business/components/api/test/components/request/ApiHttpRequestForm.vue @@ -39,6 +39,7 @@ :active-text="$t('api_test.request.refer_to_environment')" @change="useEnvironmentChange"> {{$t('api_test.request.follow_redirects')}} + {{$t('api_test.request.do_multipart_post')}} diff --git a/frontend/src/business/components/api/test/model/JMX.js b/frontend/src/business/components/api/test/model/JMX.js index 0d02ecff8c..6c57e47486 100644 --- a/frontend/src/business/components/api/test/model/JMX.js +++ b/frontend/src/business/components/api/test/model/JMX.js @@ -337,6 +337,7 @@ export class HTTPSamplerProxy extends DefaultTestElement { } this.boolProp("HTTPSampler.use_keepalive", options.keepalive, true); + this.boolProp("HTTPSampler.DO_MULTIPART_POST", options.doMultipartPost, false); } } diff --git a/frontend/src/business/components/api/test/model/ScenarioModel.js b/frontend/src/business/components/api/test/model/ScenarioModel.js index e1c8d79763..a10d6e3c56 100644 --- a/frontend/src/business/components/api/test/model/ScenarioModel.js +++ b/frontend/src/business/components/api/test/model/ScenarioModel.js @@ -346,6 +346,7 @@ export class HttpRequest extends Request { this.environment = options.environment; this.useEnvironment = options.useEnvironment; this.debugReport = undefined; + this.doMultipartPost = options.doMultipartPost; this.connectTimeout = options.connectTimeout || 60 * 1000; this.responseTimeout = options.responseTimeout; this.followRedirects = options.followRedirects === undefined ? true : options.followRedirects; @@ -987,7 +988,7 @@ class JMXHttpRequest { this.connectTimeout = request.connectTimeout; this.responseTimeout = request.responseTimeout; this.followRedirects = request.followRedirects; - + this.doMultipartPost = request.doMultipartPost; } } diff --git a/frontend/src/business/components/xpack b/frontend/src/business/components/xpack index cc38137a69..06d935cd1d 160000 --- a/frontend/src/business/components/xpack +++ b/frontend/src/business/components/xpack @@ -1 +1 @@ -Subproject commit cc38137a69a0f20fadece9c0f9f50a9468c4ace9 +Subproject commit 06d935cd1d22ab36f09763745c2aff8ad3fb08c1 diff --git a/frontend/src/i18n/en-US.js b/frontend/src/i18n/en-US.js index 9986e5cf4a..0fa27d7b0d 100644 --- a/frontend/src/i18n/en-US.js +++ b/frontend/src/i18n/en-US.js @@ -504,6 +504,7 @@ export default { connect_timeout: "Connect Timeout", response_timeout: "Response Timeout", follow_redirects: "Follow Redirects", + do_multipart_post: "Use multipart/form-data for POST", body_upload_limit_size: "The file size does not exceed 500 MB", condition: "condition", condition_variable: "Variable, e.g: ${var}", diff --git a/frontend/src/i18n/zh-CN.js b/frontend/src/i18n/zh-CN.js index 3ca1f88a10..6ca3aa5277 100644 --- a/frontend/src/i18n/zh-CN.js +++ b/frontend/src/i18n/zh-CN.js @@ -505,6 +505,7 @@ export default { connect_timeout: "连接超时", response_timeout: "响应超时", follow_redirects: "跟随重定向", + do_multipart_post: "对 POST 使用 multipart/form-data", body_upload_limit_size: "上传文件大小不能超过 500 MB!", condition: "条件", condition_variable: "变量,例如: ${var}", diff --git a/frontend/src/i18n/zh-TW.js b/frontend/src/i18n/zh-TW.js index f2ca497ec1..0619038219 100644 --- a/frontend/src/i18n/zh-TW.js +++ b/frontend/src/i18n/zh-TW.js @@ -505,6 +505,7 @@ export default { connect_timeout: "連接超時", response_timeout: "響應超時", follow_redirects: "跟隨重定向", + do_multipart_post: "對 POST 使用 multipart/form-data", body_upload_limit_size: "上傳文件大小不能超過 500 MB!", condition: "條件", condition_variable: "變量,例如: ${var}",