From f428a212795f2574a90e26d462063e0ac7872c02 Mon Sep 17 00:00:00 2001 From: Manda Putra Date: Sun, 3 Oct 2021 06:52:56 +0700 Subject: [PATCH] feat: parse body from url params --- packages/hoppscotch-app/pages/index.vue | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/hoppscotch-app/pages/index.vue b/packages/hoppscotch-app/pages/index.vue index fc161f8c7..33453d804 100644 --- a/packages/hoppscotch-app/pages/index.vue +++ b/packages/hoppscotch-app/pages/index.vue @@ -136,7 +136,10 @@ import { } from "~/helpers/utils/composables" import { loadRequestFromSync, startRequestSync } from "~/helpers/fb/request" import { onLoggedIn } from "~/helpers/fb/auth" -import { HoppRESTRequest } from "~/helpers/types/HoppRESTRequest" +import { + FormDataKeyValue, + HoppRESTRequest, +} from "~/helpers/types/HoppRESTRequest" import { oauthRedirect } from "~/helpers/oauth" import { HoppRESTAuthOAuth2 } from "~/helpers/types/HoppRESTAuth" import useWindowSize from "~/helpers/utils/useWindowSize" @@ -161,6 +164,17 @@ function bindRequestToURLParams() { return filtered.length > 0 ? JSON.stringify(filtered) : null }) + const contentType = request.value.body.contentType + + const body = computed(() => { + if (contentType === "multipart/form-data") { + const body = request.value.body.body as FormDataKeyValue[] + const filtered = body.filter((x) => x.key !== "") + return filtered.length > 0 ? JSON.stringify(filtered) : null + } + return JSON.stringify(request.value.body) + }) + // Combine them together to a cleaner value const urlParams = computed(() => ({ v: request.value.v, @@ -168,6 +182,7 @@ function bindRequestToURLParams() { endpoint: request.value.endpoint, headers: headers.value, params: params.value, + body: JSON.stringify({ contentType, body }), })) // Watch and update accordingly