From 8707d3fdfe2ae0dbf2a84b9aeb8850f2cfb78219 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Tue, 25 Jul 2017 14:19:21 -0700 Subject: [PATCH] Autodetect XML if no content-type (Closes #368) --- app/ui/components/viewers/response-viewer.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/ui/components/viewers/response-viewer.js b/app/ui/components/viewers/response-viewer.js index e34a0178fe..f52c9dfaba 100644 --- a/app/ui/components/viewers/response-viewer.js +++ b/app/ui/components/viewers/response-viewer.js @@ -185,12 +185,19 @@ class ResponseViewer extends PureComponent { const body = iconv.decode(bodyBuffer, charset); let mode = contentType; - try { - // FEATURE: Detect JSON even without content-type - contentType.indexOf('json') === -1 && JSON.parse(body); - mode = 'application/json'; - } catch (e) { - // Nothing + + // Try to detect content-types if there isn't one + if (!mode) { + if (body.match(/^\s*<\?xml version="\d\.\d".*\?>/)) { + mode = 'application/xml'; + } else { + try { + JSON.parse(body); + mode = 'application/json'; + } catch (e) { + // Nothing + } + } } return (