From 77ea9dfac9f165956c9e700b7143142b7faa0946 Mon Sep 17 00:00:00 2001 From: Jacob Anavisca Date: Tue, 25 Feb 2020 01:35:15 -0500 Subject: [PATCH 1/6] Added regex to handle url parts --- pages/index.vue | 334 +++++++++++++++++++++++++----------------------- 1 file changed, 172 insertions(+), 162 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index 15a9461d2..53c75e54b 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -42,143 +42,145 @@ +
>)?[^\/]*|)(\/?.*)$/ + ); + let url = uriRegex[1]; + let path = uriRegex[4]; + this.url = url; + this.path = path; + } + }, url: { get() { return this.$store.state.request.url; From 8cc7b525d91c86667ba1c2f862f765ebbf54a967 Mon Sep 17 00:00:00 2001 From: Jacob Anavisca Date: Tue, 25 Feb 2020 01:35:15 -0500 Subject: [PATCH 2/6] Added regex to handle url parts --- pages/index.vue | 44 +- pages/index.vue.orig | 2937 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 2970 insertions(+), 11 deletions(-) create mode 100644 pages/index.vue.orig diff --git a/pages/index.vue b/pages/index.vue index 2448bfa9f..6e86bea98 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -182,19 +182,27 @@ id="url" name="url" type="url" - v-model="url" - /> - -
  • - -
  • +
    +
  • + + +
  • +
    + +
    • >)?[^\/]*|)(\/?.*)$/ + ); + let url = uriRegex[1]; + let path = uriRegex[4]; + this.url = url; + this.path = path; + } + }, url: { get() { return this.$store.state.request.url diff --git a/pages/index.vue.orig b/pages/index.vue.orig new file mode 100644 index 000000000..0325c80e4 --- /dev/null +++ b/pages/index.vue.orig @@ -0,0 +1,2937 @@ + + + From 492d1cfa8ffd6b873df07183c9ff88ed1b8596af Mon Sep 17 00:00:00 2001 From: Jacob Anavisca Date: Tue, 25 Feb 2020 22:36:14 -0500 Subject: [PATCH 3/6] url api and updated test --- pages/index.vue | 87 +++++++---------------------- store/state.js | 1 + tests/e2e/integration/proxy.spec.js | 2 - 3 files changed, 22 insertions(+), 68 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index 6e86bea98..7ca0e09fd 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -185,24 +185,6 @@ v-model="uri" />
    • -
      -
    • - - -
    • -
      -
    -
    • { } export const findStatusGroup = responseStatus => statusCategories.find(status => status.statusCodeRegex.test(responseStatus)) - export default { directives: { textareaAutoHeight, }, - components: { "pw-section": section, "pw-toggle": () => import("../components/toggle"), @@ -1412,13 +1391,11 @@ 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. */ @@ -1430,9 +1407,7 @@ export default { "text/html", "text/plain", ], - commonHeaders, - showRequestModal: false, editRequest: {}, urlExcludes: {}, @@ -1507,7 +1482,6 @@ export default { } else { path = path + queryString } - this.path = path }, deep: true, @@ -1543,16 +1517,29 @@ export default { computed: { uri: { get() { - return this.url + this.path; + return this.$store.state.request.uri ? + this.$store.state.request.uri + : this.url + this.path; }, set(value) { - let uriRegex = value.match( - /^((http[s]?:\/\/)?(<<[^\/]+>>)?[^\/]*|)(\/?.*)$/ - ); - let url = uriRegex[1]; - let path = uriRegex[4]; - this.url = url; - this.path = path; + this.$store.commit("setState", { value, attribute: "uri" }) + let url; + if (this.preRequestScript && this.showPreRequestScript) { + const environmentVariables = getEnvironmentVariablesFromScript(this.preRequestScript); + url = parseTemplateString(value, environmentVariables); + } + try { + url = new URL(url); + this.url = url.origin; + this.path = url.pathname; + } catch(error) { + console.log(error) + let uriRegex = value.match( + /^((http[s]?:\/\/)?(<<[^\/]+>>)?[^\/]*|)(\/?.*)$/ + ); + this.url = uriRegex[1]; + this.path = uriRegex[4]; + } } }, url: { @@ -1783,7 +1770,6 @@ export default { }) }, }, - selectedRequest() { return this.$store.state.postwoman.selectedRequest }, @@ -2019,31 +2005,26 @@ export default { if (typeof requestOptions.data === "string") { requestOptions.data = parseTemplateString(requestOptions.data) } - return await sendNetworkRequest(requestOptions, this.$store) }, async sendRequest() { this.$toast.clear() this.$store.state.postwoman.settings.SCROLL_INTO_ENABLED && this.scrollInto("response") - if (!this.isValidURL) { this.$toast.error(this.$t("url_invalid_format"), { icon: "error", }) return } - // Start showing the loading bar as soon as possible. // The nuxt axios module will hide it when the request is made. this.$nuxt.$loading.start() - if (this.$refs.response.$el.classList.contains("hidden")) { this.$refs.response.$el.classList.toggle("hidden") } this.previewEnabled = false this.response.status = this.$t("fetching") this.response.body = this.$t("loading") - const auth = this.auth === "Basic Auth" ? { @@ -2051,29 +2032,23 @@ export default { password: this.httpPassword, } : null - let headers = {} let headersObject = {} - Object.keys(headers).forEach(id => { headersObject[headers[id].key] = headers[id].value }) headers = headersObject - // If the request has a body, we want to ensure Content-Length and // Content-Type are sent. let requestBody if (this.hasRequestBody) { requestBody = this.rawInput ? this.rawParams : this.rawRequestBody - Object.assign(headers, { //'Content-Length': requestBody.length, "Content-Type": `${this.contentType}; charset=utf-8`, }) } - requestBody = requestBody ? requestBody.toString() : null - if (this.files.length !== 0) { const formData = new FormData() for (let i = 0; i < this.files.length; i++) { @@ -2083,37 +2058,30 @@ export default { formData.append("data", requestBody) requestBody = formData } - // If the request uses a token for auth, we want to make sure it's sent here. if (this.auth === "Bearer Token" || this.auth === "OAuth 2.0") headers["Authorization"] = `Bearer ${this.bearerToken}` - headers = Object.assign( // Clone the app headers object first, we don't want to // mutate it with the request headers added by default. Object.assign({}, this.headers) - // We make our temporary headers object the source so // that you can override the added headers if you // specify them. // headers ) - Object.keys(headers).forEach(id => { headersObject[headers[id].key] = headers[id].value }) headers = headersObject - try { const startTime = Date.now() - const payload = await this.makeRequest( auth, headers, requestBody, this.showPreRequestScript && this.preRequestScript ) - const duration = Date.now() - startTime this.$toast.info(this.$t("finished_in", { duration }), { icon: "done", @@ -2121,13 +2089,10 @@ export default { ;(() => { const status = (this.response.status = payload.status) const headers = (this.response.headers = payload.headers) - // We don't need to bother parsing JSON, axios already handles it for us! const body = (this.response.body = payload.data) - const date = new Date().toLocaleDateString() const time = new Date().toLocaleTimeString() - // Addition of an entry to the history component. const entry = { label: this.requestName, @@ -2149,7 +2114,6 @@ export default { } } })() - // tests const syntheticResponse = { status: this.response.status, @@ -2166,7 +2130,6 @@ export default { this.response.headers = error.response.headers this.response.status = error.response.status this.response.body = error.response.data - // Addition of an entry to the history component. const entry = { label: this.requestName, @@ -2235,7 +2198,6 @@ export default { removeRequestHeader(index) { // .slice() gives us an entirely new array rather than giving us just the reference const oldHeaders = this.headers.slice() - this.$store.commit("removeHeaders", index) this.$toast.error(this.$t("deleted"), { icon: "delete", @@ -2255,7 +2217,6 @@ export default { removeRequestParam(index) { // .slice() gives us an entirely new array rather than giving us just the reference const oldParams = this.params.slice() - this.$store.commit("removeParams", index) this.$toast.error(this.$t("deleted"), { icon: "delete", @@ -2275,7 +2236,6 @@ export default { removeRequestBodyParam(index) { // .slice() gives us an entirely new array rather than giving us just the reference const oldBodyParams = this.bodyParams.slice() - this.$store.commit("removeBodyParams", index) this.$toast.error(this.$t("deleted"), { icon: "delete", @@ -2408,7 +2368,6 @@ export default { .map(item => flat(item)) const deeps = ["headers", "params"].map(item => deep(item)) const bodyParams = this.rawInput ? [flat("rawParams")] : [deep("bodyParams")] - history.replaceState( window.location.href, "", @@ -2555,7 +2514,6 @@ export default { }) return } - this.editRequest = { url: this.url, path: this.path, @@ -2573,11 +2531,9 @@ export default { contentType: this.contentType, requestType: this.requestType, } - if (this.selectedRequest.url) { this.editRequest = Object.assign({}, this.selectedRequest, this.editRequest) } - this.showRequestModal = true }, hideRequestModal() { @@ -2762,7 +2718,6 @@ export default { httpPassword: true, bearerToken: true, } - if (Object.keys(this.$route.query).length) this.setRouteQueries(this.$route.query) this.$watch( vm => [ diff --git a/store/state.js b/store/state.js index 1df17674a..a9a5bec15 100644 --- a/store/state.js +++ b/store/state.js @@ -1,6 +1,7 @@ export default () => ({ request: { method: "GET", + uri: "", url: "https://httpbin.org", path: "/get", label: "", diff --git a/tests/e2e/integration/proxy.spec.js b/tests/e2e/integration/proxy.spec.js index 455bc3f86..f5579b11b 100644 --- a/tests/e2e/integration/proxy.spec.js +++ b/tests/e2e/integration/proxy.spec.js @@ -3,8 +3,6 @@ describe("Proxy disabled - local request", () => { cy.seedAndVisit("catapi", "/?url=https://api.thecatapi.com&path=") .get("#url") .then(el => expect(el.val() === "https://api.thecatapi.com").to.equal(true)) - .get("#path") - .then(el => expect(el.val() === "").to.equal(true)) .get("#response-details-wrapper") .should($wrapper => { expect($wrapper).to.contain("FAKE Cat API") From eac838198143b92ef34d22d729783d8d75cc3f65 Mon Sep 17 00:00:00 2001 From: Jacob Anavisca Date: Tue, 25 Feb 2020 22:52:58 -0500 Subject: [PATCH 4/6] Minor get uri update --- pages/index.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index 7ca0e09fd..c1639cc78 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1517,9 +1517,9 @@ export default { computed: { uri: { get() { - return this.$store.state.request.uri ? - this.$store.state.request.uri - : this.url + this.path; + return this.url + this.path ? + this.url + this.path + : this.$store.state.request.uri; }, set(value) { this.$store.commit("setState", { value, attribute: "uri" }) From 5849d351c2321dcb5b0ecf3e5b9381b162e04182 Mon Sep 17 00:00:00 2001 From: Jacob Anavisca Date: Tue, 25 Feb 2020 23:43:27 -0500 Subject: [PATCH 5/6] Minor ui update --- pages/index.vue | 316 ++++++++++++++++++++++++------------------------ 1 file changed, 160 insertions(+), 156 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index c1639cc78..53e76da61 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -37,143 +37,145 @@
        -
      • - - - - - - - - -
      • +
        +
      • + + + + + + + + +
      • +
      • -
      • - - -
      • -
      • - - -
      • +
        +
      • + + +
      • +
      +
      + + +
      • From 54207e3f337fdc1e66bd5809cc2a938dd4c07af0 Mon Sep 17 00:00:00 2001 From: Jacob Anavisca Date: Wed, 26 Feb 2020 00:02:22 -0500 Subject: [PATCH 6/6] uri update when selecting request --- pages/index.vue | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index 53e76da61..9b4d00666 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1493,6 +1493,7 @@ export default { selectedRequest(newValue, oldValue) { // @TODO: Convert all variables to single request variable if (!newValue) return + this.uri = newValue.url + newValue.path this.url = newValue.url this.path = newValue.path this.method = newValue.method @@ -1521,9 +1522,9 @@ export default { computed: { uri: { get() { - return this.url + this.path ? - this.url + this.path - : this.$store.state.request.uri; + return this.$store.state.request.uri ? + this.$store.state.request.uri + : this.url + this.path; }, set(value) { this.$store.commit("setState", { value, attribute: "uri" }) @@ -1974,6 +1975,7 @@ export default { handleUseHistory({ label, method, url, path, usesScripts, preRequestScript }) { this.label = label this.method = method + this.uri = url + path this.url = url this.path = path this.showPreRequestScript = usesScripts