From ff76a7e69ddd25bb577b6e7fe259341661131f1c Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Mon, 3 Aug 2020 17:06:45 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=8E=AF=E5=A2=83=E5=9F=9F?= =?UTF-8?q?=E5=90=8D=E5=8F=AF=E4=BB=A5=E8=AE=BE=E7=BD=AE=E4=B8=BADbeaseUrl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/components/ApiEnvironmentConfig.vue | 2 +- .../environment/EnvironmentEdit.vue | 40 ++++++++----------- .../components/request/ApiHttpRequestForm.vue | 13 +++--- .../api/test/model/ScenarioModel.js | 16 +++----- .../common/components/MsAsideContainer.vue | 8 +++- .../common/components/MsAsideItem.vue | 6 ++- 6 files changed, 39 insertions(+), 46 deletions(-) diff --git a/frontend/src/business/components/api/test/components/ApiEnvironmentConfig.vue b/frontend/src/business/components/api/test/components/ApiEnvironmentConfig.vue index 0971806a46..0bb0fa5c5d 100644 --- a/frontend/src/business/components/api/test/components/ApiEnvironmentConfig.vue +++ b/frontend/src/business/components/api/test/components/ApiEnvironmentConfig.vue @@ -2,7 +2,7 @@ - diff --git a/frontend/src/business/components/api/test/components/environment/EnvironmentEdit.vue b/frontend/src/business/components/api/test/components/environment/EnvironmentEdit.vue index 356943977d..0f21c11a20 100644 --- a/frontend/src/business/components/api/test/components/environment/EnvironmentEdit.vue +++ b/frontend/src/business/components/api/test/components/environment/EnvironmentEdit.vue @@ -42,6 +42,7 @@ import MsApiKeyValue from "../ApiKeyValue"; import MsDialogFooter from "../../../../common/components/MsDialogFooter"; import {REQUEST_HEADERS} from "../../../../../../common/js/constants"; + import {KeyValue} from "../../model/ScenarioModel"; export default { name: "EnvironmentEdit", @@ -110,39 +111,30 @@ }, validateSocket(socket) { if (!socket) return; - let socketInfo = socket.split(":"); - if (socketInfo.length > 2) { - return false; + let urlStr = this.environment.protocol + '://' + socket; + let url = {}; + try { + url = new URL(urlStr); + } catch (e) { + return false } - let host = socketInfo[0]; - let port = socketInfo[1]; - if (!this.validateHost(host) || !(port == undefined || this.validatePort(port))) { - return false; + + this.environment.port = url.port; + this.environment.domain = decodeURIComponent(url.hostname); + if (url.port) { + this.environment.socket = this.environment.domain + ':' + url.port + url.pathname; + } else { + this.environment.socket = this.environment.domain + url.pathname; } - this.environment.domain = host; - this.environment.port = port; return true; }, - validateHost(host) { - let hostReg = /^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/; - if (hostReg.test(host) || host === 'localhost') { - return true; - } - return false; - }, - validatePort(port) { - let portReg = /^[1-9]\d*$/; - if (portReg.test(port) && 1 <= 1*port && 1*port <= 65535){ - return true - } - return false; - }, + cancel() { this.$emit('close'); }, clearValidate() { this.$refs["from"].clearValidate(); - } + }, }, } 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 5801753c87..8392e35be7 100644 --- a/frontend/src/business/components/api/test/components/request/ApiHttpRequestForm.vue +++ b/frontend/src/business/components/api/test/components/request/ApiHttpRequestForm.vue @@ -100,7 +100,7 @@ {validator: validateURL, trigger: 'blur'} ], path: [ - {max: 500, required: true, message: this.$t('commons.input_limit', [1, 500]), trigger: 'blur'}, + {max: 500, message: this.$t('commons.input_limit', [0, 500]), trigger: 'blur'}, ] }, headerSuggestions: REQUEST_HEADERS @@ -117,13 +117,12 @@ }, pathChange() { if (!this.request.path) return; - if (!this.request.path.startsWith('/')) { - this.request.path = '/' + this.request.path; - } let url = this.getURL(this.displayUrl); - this - .request.path = decodeURIComponent(url.pathname); - this.request.urlWirhEnv = decodeURIComponent(url.origin + url.pathname); + let urlStr = url.origin + url.pathname; + let envUrl = this.request.environment.protocol + '://' + this.request.environment.socket; + let test = urlStr.substring(envUrl.length, urlStr.length); + + this.request.path = decodeURIComponent(test); }, getURL(urlStr) { try { diff --git a/frontend/src/business/components/api/test/model/ScenarioModel.js b/frontend/src/business/components/api/test/model/ScenarioModel.js index ec15ee859e..12d09da4f9 100644 --- a/frontend/src/business/components/api/test/model/ScenarioModel.js +++ b/frontend/src/business/components/api/test/model/ScenarioModel.js @@ -285,11 +285,6 @@ export class HttpRequest extends Request { isValid: false, info: 'api_test.request.please_configure_environment_in_scenario' } - } else if (!this.path) { - return { - isValid: false, - info: 'api_test.request.input_path' - } } } else { if (!this.url) { @@ -668,12 +663,11 @@ class JMXHttpRequest { this.protocol = url.protocol.split(":")[0]; this.pathname = this.getPostQueryParameters(request, decodeURIComponent(url.pathname)); } else { - if (environment) { - this.port = environment.port; - this.protocol = environment.protocol; - this.domain = environment.domain; - } - this.path = this.getPostQueryParameters(request, decodeURIComponent(request.path)); + this.port = environment.port; + this.protocol = environment.protocol; + this.domain = environment.domain; + let url = new URL(environment.protocol + "://" + environment.socket); + this.path = this.getPostQueryParameters(request, decodeURIComponent(url.pathname)); } } } diff --git a/frontend/src/business/components/common/components/MsAsideContainer.vue b/frontend/src/business/components/common/components/MsAsideContainer.vue index e040a5a491..982a542550 100644 --- a/frontend/src/business/components/common/components/MsAsideContainer.vue +++ b/frontend/src/business/components/common/components/MsAsideContainer.vue @@ -1,7 +1,7 @@