Skip to content

Commit f5638c9

Browse files
authored
Merge branch 'master' into bug/3817-query-allowreserved-encoding
2 parents c469ad7 + 2649e63 commit f5638c9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/http.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ export default function http(url, request = {}) {
6767
// exported for testing
6868
export const shouldDownloadAsText = (contentType = '') => /json|xml|yaml|text/.test(contentType)
6969

70+
function parseBody(body) {
71+
if (/^\s*\{/.test(body)) {
72+
return JSON.parse(body)
73+
}
74+
return jsYaml.safeLoad(body)
75+
}
76+
7077
// Serialize the response, returns a promise with headers and the body part of the hash
7178
export function serializeRes(oriRes, url, {loadSpec = false} = {}) {
7279
const res = {
@@ -88,8 +95,7 @@ export function serializeRes(oriRes, url, {loadSpec = false} = {}) {
8895

8996
if (useText) {
9097
try {
91-
// Optimistically try to convert all bodies
92-
const obj = jsYaml.safeLoad(body)
98+
const obj = parseBody(body)
9399
res.body = obj
94100
res.obj = obj
95101
}

0 commit comments

Comments
 (0)