From 78693964d8a9cabfd49bf1f3dd910ed006cac1be Mon Sep 17 00:00:00 2001 From: Rishabh Agarwal <45998880+RishabhAgarwal-2001@users.noreply.github.com> Date: Mon, 24 Jan 2022 16:22:24 +0530 Subject: [PATCH] feat: Ensure Method In Endpoint (#2083) --- packages/hoppscotch-app/components/http/Request.vue | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/hoppscotch-app/components/http/Request.vue b/packages/hoppscotch-app/components/http/Request.vue index f14e5ed6c..353eda679 100644 --- a/packages/hoppscotch-app/components/http/Request.vue +++ b/packages/hoppscotch-app/components/http/Request.vue @@ -307,6 +307,8 @@ const newSendRequest = async () => { return } + ensureMethodInEndpoint() + loading.value = true // Double calling is because the function returns a TaskEither than should be executed @@ -345,6 +347,17 @@ const newSendRequest = async () => { } } +const ensureMethodInEndpoint = () => { + if (!/^http[s]?:\/\//.test(newEndpoint.value)) { + const domain = newEndpoint.value.split(/[/:#?]+/)[0] + if (domain === "localhost" || /([0-9]+\.)*[0-9]/.test(domain)) { + setRESTEndpoint("http://" + newEndpoint.value) + } else { + setRESTEndpoint("https://" + newEndpoint.value) + } + } +} + const onPasteUrl = (e: { event: ClipboardEvent; previousValue: string }) => { if (!e) return