fix: race condition mutating defaultRESTRequest
This commit is contained in:
@@ -233,12 +233,9 @@ watch(bulkHeaders, () => {
|
||||
.split("\n")
|
||||
.filter((x) => x.trim().length > 0 && x.includes(":"))
|
||||
.map((item) => ({
|
||||
key: item
|
||||
.substring(0, item.indexOf(":"))
|
||||
.trimLeft()
|
||||
.replace(/^\/\//, ""),
|
||||
key: item.substring(0, item.indexOf(":")).trimLeft().replace(/^#/, ""),
|
||||
value: item.substring(item.indexOf(":") + 1).trimLeft(),
|
||||
active: !item.trim().startsWith("//"),
|
||||
active: !item.trim().startsWith("#"),
|
||||
}))
|
||||
|
||||
const filteredHeaders = workingHeaders.value.filter((x) => x.key !== "")
|
||||
@@ -251,15 +248,16 @@ watch(bulkHeaders, () => {
|
||||
console.error(e)
|
||||
}
|
||||
})
|
||||
|
||||
watch(workingHeaders, (newHeadersList) => {
|
||||
// If we are in bulk mode, don't apply direct changes
|
||||
if (bulkMode.value) return
|
||||
|
||||
try {
|
||||
const currentBulkHeaders = bulkHeaders.value.split("\n").map((item) => ({
|
||||
key: item.substring(0, item.indexOf(":")).trimLeft().replace(/^\/\//, ""),
|
||||
key: item.substring(0, item.indexOf(":")).trimLeft().replace(/^#/, ""),
|
||||
value: item.substring(item.indexOf(":") + 1).trimLeft(),
|
||||
active: !item.trim().startsWith("//"),
|
||||
active: !item.trim().startsWith("#"),
|
||||
}))
|
||||
|
||||
const filteredHeaders = newHeadersList.filter((x) => x.key !== "")
|
||||
@@ -267,7 +265,7 @@ watch(workingHeaders, (newHeadersList) => {
|
||||
if (!isEqual(currentBulkHeaders, filteredHeaders)) {
|
||||
bulkHeaders.value = filteredHeaders
|
||||
.map((header) => {
|
||||
return `${header.active ? "" : "//"}${header.key}: ${header.value}`
|
||||
return `${header.active ? "" : "#"}${header.key}: ${header.value}`
|
||||
})
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
@@ -224,12 +224,9 @@ watch(bulkParams, () => {
|
||||
.split("\n")
|
||||
.filter((x) => x.trim().length > 0 && x.includes(":"))
|
||||
.map((item) => ({
|
||||
key: item
|
||||
.substring(0, item.indexOf(":"))
|
||||
.trimLeft()
|
||||
.replace(/^\/\//, ""),
|
||||
key: item.substring(0, item.indexOf(":")).trimLeft().replace(/^#/, ""),
|
||||
value: item.substring(item.indexOf(":") + 1).trimLeft(),
|
||||
active: !item.trim().startsWith("//"),
|
||||
active: !item.trim().startsWith("#"),
|
||||
}))
|
||||
|
||||
const filteredParams = workingParams.value.filter((x) => x.key !== "")
|
||||
@@ -242,15 +239,16 @@ watch(bulkParams, () => {
|
||||
console.error(e)
|
||||
}
|
||||
})
|
||||
|
||||
watch(workingParams, (newParamsList) => {
|
||||
// If we are in bulk mode, don't apply direct changes
|
||||
if (bulkMode.value) return
|
||||
|
||||
try {
|
||||
const currentBulkParams = bulkParams.value.split("\n").map((item) => ({
|
||||
key: item.substring(0, item.indexOf(":")).trimLeft().replace(/^\/\//, ""),
|
||||
key: item.substring(0, item.indexOf(":")).trimLeft().replace(/^#/, ""),
|
||||
value: item.substring(item.indexOf(":") + 1).trimLeft(),
|
||||
active: !item.trim().startsWith("//"),
|
||||
active: !item.trim().startsWith("#"),
|
||||
}))
|
||||
|
||||
const filteredParams = newParamsList.filter((x) => x.key !== "")
|
||||
@@ -258,7 +256,7 @@ watch(workingParams, (newParamsList) => {
|
||||
if (!isEqual(currentBulkParams, filteredParams)) {
|
||||
bulkParams.value = filteredParams
|
||||
.map((param) => {
|
||||
return `${param.active ? "" : "//"}${param.key}: ${param.value}`
|
||||
return `${param.active ? "" : "#"}${param.key}: ${param.value}`
|
||||
})
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import clone from "lodash/clone"
|
||||
import { FormDataKeyValue, HoppRESTRequest } from "@hoppscotch/data"
|
||||
import { isJSONContentType } from "./utils/contenttypes"
|
||||
import { defaultRESTRequest } from "~/newstore/RESTSession"
|
||||
import { getDefaultRESTRequest } from "~/newstore/RESTSession"
|
||||
|
||||
/**
|
||||
* Handles translations for all the hopp.io REST Shareable URL params
|
||||
@@ -14,7 +13,7 @@ export function translateExtURLParams(
|
||||
}
|
||||
|
||||
function parseV0ExtURL(urlParams: Record<string, any>): HoppRESTRequest {
|
||||
const resolvedReq = clone(defaultRESTRequest)
|
||||
const resolvedReq = getDefaultRESTRequest()
|
||||
|
||||
if (urlParams.method && typeof urlParams.method === "string") {
|
||||
resolvedReq.method = urlParams.method
|
||||
@@ -91,7 +90,7 @@ function parseV0ExtURL(urlParams: Record<string, any>): HoppRESTRequest {
|
||||
}
|
||||
|
||||
function parseV1ExtURL(urlParams: Record<string, any>): HoppRESTRequest {
|
||||
const resolvedReq = clone(defaultRESTRequest)
|
||||
const resolvedReq = getDefaultRESTRequest()
|
||||
|
||||
if (urlParams.headers && typeof urlParams.headers === "string") {
|
||||
resolvedReq.headers = JSON.parse(urlParams.headers)
|
||||
|
||||
@@ -23,7 +23,7 @@ type RESTSession = {
|
||||
saveContext: HoppRequestSaveContext | null
|
||||
}
|
||||
|
||||
export const defaultRESTRequest: HoppRESTRequest = {
|
||||
export const getDefaultRESTRequest = (): HoppRESTRequest => ({
|
||||
v: RESTReqSchemaVersion,
|
||||
endpoint: "https://echo.hoppscotch.io",
|
||||
name: "Untitled request",
|
||||
@@ -40,10 +40,10 @@ export const defaultRESTRequest: HoppRESTRequest = {
|
||||
contentType: null,
|
||||
body: null,
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
const defaultRESTSession: RESTSession = {
|
||||
request: defaultRESTRequest,
|
||||
request: getDefaultRESTRequest(),
|
||||
response: null,
|
||||
testResults: null,
|
||||
saveContext: null,
|
||||
@@ -387,7 +387,7 @@ export function getRESTSaveContext() {
|
||||
}
|
||||
|
||||
export function resetRESTRequest() {
|
||||
setRESTRequest(defaultRESTRequest)
|
||||
setRESTRequest(getDefaultRESTRequest())
|
||||
}
|
||||
|
||||
export function setRESTEndpoint(newEndpoint: string) {
|
||||
|
||||
Reference in New Issue
Block a user