From 6ebcecae80d74a5249eca99418500b0016f0240c Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Wed, 10 Jun 2020 20:05:23 -0400 Subject: [PATCH 1/2] Added support for full content-type headers in isJSONContentType --- functions/utils/contenttypes.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/functions/utils/contenttypes.js b/functions/utils/contenttypes.js index 4e9173cee..d9f1d8177 100644 --- a/functions/utils/contenttypes.js +++ b/functions/utils/contenttypes.js @@ -9,9 +9,19 @@ export const knownContentTypes = [ ] export function isJSONContentType(contentType) { - return ( - contentType === "application/json" || - contentType === "application/vnd.api+json" || - contentType === "application/hal+json" - ) + if (contentType.includes(";")) { + const [justContentType] = contentType.split(";") + + return ( + justContentType === "application/json" || + justContentType === "application/vnd.api+json" || + justContentType === "application/hal+json" + ) + } else { + return ( + contentType === "application/json" || + contentType === "application/vnd.api+json" || + contentType === "application/hal+json" + ) + } } From d111e219c2a52cabee9110d225e0b99fd7c746e0 Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Wed, 10 Jun 2020 20:05:51 -0400 Subject: [PATCH 2/2] Hide download response button for non-JSON responses --- pages/index.vue | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pages/index.vue b/pages/index.vue index 62d2769d6..1a0ae504e 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -973,7 +973,7 @@ class="icon" @click="downloadResponse" ref="downloadResponse" - v-if="response.body" + v-if="response.body && canDownloadResponse" v-tooltip="$t('download_file')" > get_app @@ -1612,6 +1612,14 @@ export default { isJSONContentType(this.contentType) ) }, + canDownloadResponse() { + return ( + this.response && + this.response.headers && + this.response.headers["content-type"] && + isJSONContentType(this.response.headers["content-type"]) + ) + }, uri: { get() { return this.$store.state.request.uri ? this.$store.state.request.uri : this.url + this.path