Skip to content

Commit 0de117b

Browse files
committed
fix: better content-type check
1 parent 3d954e0 commit 0de117b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/api.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ const render = ({ response, flags }) => {
6161
const { headers, timings, requestUrl: uri, body } = response
6262
if (!flags.pretty) return console.log(body.toString())
6363

64-
const contentType = headers['content-type'].toLowerCase()
64+
const contentType = headers['content-type'].split(';')[0].toLowerCase()
6565
const time = prettyMs(timings.phases.total)
6666
const serverTiming = headers['server-timing']
6767
const id = headers['x-request-id']
6868

6969
const printMode = (() => {
7070
if (body.toString().startsWith('data:')) return 'base64'
71-
if (!contentType.includes('utf')) return 'image'
71+
if (contentType !== 'application/json') return 'image'
7272
})()
7373

7474
switch (printMode) {
@@ -84,8 +84,8 @@ const render = ({ response, flags }) => {
8484
console.log()
8585
break
8686
default: {
87-
const isText = contentType.includes('text/plain')
88-
const isHtml = contentType.includes('text/html')
87+
const isText = contentType === 'text/plain'
88+
const isHtml = contentType === 'text/html'
8989
const output = isText || isHtml ? body.toString() : JSON.parse(body)
9090
print.json(output, flags)
9191
break

0 commit comments

Comments
 (0)