From 90a6315e2b4d25a3a61f3eb5967342b7a874c7b2 Mon Sep 17 00:00:00 2001 From: Leonardo Matos Date: Tue, 17 Mar 2020 10:40:23 -0300 Subject: [PATCH 1/3] perf(vue): 'validContentTypes' and 'knownContentTypes' can be computed --- pages/index.vue | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index 7022ceffa..63dad1bb1 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1400,22 +1400,6 @@ export default { showTokenList: false, showTokenRequest: false, showTokenRequestList: false, - /** - * These are content types that can be automatically - * serialized by postwoman. - */ - knownContentTypes: ["application/json", "application/x-www-form-urlencoded"], - /** - * These are a list of Content Types known to Postwoman. - */ - validContentTypes: [ - "application/json", - "application/hal+json", - "application/xml", - "application/x-www-form-urlencoded", - "text/html", - "text/plain", - ], commonHeaders, showRequestModal: false, editRequest: {}, @@ -1532,6 +1516,22 @@ export default { }, }, computed: { + /** + * These are content types that can be automatically + * serialized by postwoman. + */ + knownContentTypes: () => ["application/json", "application/x-www-form-urlencoded"], + /** + * These are a list of Content Types known to Postwoman. + */ + validContentTypes: () => [ + "application/json", + "application/hal+json", + "application/xml", + "application/x-www-form-urlencoded", + "text/html", + "text/plain", + ], uri: { get() { return this.$store.state.request.uri ? this.$store.state.request.uri : this.url + this.path From 1f38c25e6a70a0541ae048885de3d8363dc71620 Mon Sep 17 00:00:00 2001 From: Leonardo Matos Date: Tue, 17 Mar 2020 10:53:36 -0300 Subject: [PATCH 2/3] fix(req-body): enable parameters list for form encoded only disable raw input toggle when not content type 'application/x-www-form-urlencoded' --- pages/index.vue | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index 63dad1bb1..2af4958e2 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -223,7 +223,7 @@
  • - + {{ $t("raw_input") }} @@ -1432,8 +1432,8 @@ export default { ]) }, }, - contentType(val) { - this.rawInput = !this.knownContentTypes.includes(val) + canListParameters(canToggleRaw) { + this.rawInput = !canToggleRaw }, rawInput(status) { if (status && this.rawParams === "") { @@ -1532,6 +1532,9 @@ export default { "text/html", "text/plain", ], + canListParameters() { + return this.contentType === "application/x-www-form-urlencoded" + }, uri: { get() { return this.$store.state.request.uri ? this.$store.state.request.uri : this.url + this.path From 8469d13a12a733f6f88ebaa1fd75f8c579023d6d Mon Sep 17 00:00:00 2001 From: Leonardo Matos Date: Tue, 17 Mar 2020 11:30:45 -0300 Subject: [PATCH 3/3] fix(req-body): fix preseting default body (raw) by content type --- pages/index.vue | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index 2af4958e2..e2f823396 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1435,12 +1435,25 @@ export default { canListParameters(canToggleRaw) { this.rawInput = !canToggleRaw }, - rawInput(status) { - if (status && this.rawParams === "") { - this.rawParams = "{}" - } else { - this.setRouteQueryState() + contentType(contentType) { + switch (contentType) { + case "application/json": + case "application/hal+json": + if (!(this.rawParams.charAt(0) in ['"', "{", "["])) { + this.rawParams = "{}" + } + break + case "application/xml": + if (this.rawParams.charAt(0) !== "<" || this.rawParams === "") { + this.rawParams = "" + } + break + case "text/html": + if (this.rawParams.charAt(0) !== "<" || this.rawParams.startsWith("" + } } + this.setRouteQueryState() }, "response.body": function(val) { if (