Skip to content

Commit 67c72c8

Browse files
jazwieckiflotwig
authored andcommitted
more permissive check for json to include application/vnd.api+j… (#5166)
* more permissive check for json to include * add json test for content-type application/vnd.api+json * cruder solution passes e2e tests locally, so let's go with that * Remove 'charset' from content-type before checking if JSON
1 parent 908c738 commit 67c72c8

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/server/lib/request.coffee

+2-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ module.exports = (options = {}) ->
381381

382382
contentTypeIsJson: (response) ->
383383
## TODO: use https://github.com/jshttp/type-is for this
384-
response?.headers?["content-type"]?.includes("application/json")
384+
## https://github.com/cypress-io/cypress/pull/5166
385+
response?.headers?["content-type"]?.split(';', 2)[0].endsWith("json")
385386

386387
parseJsonBody: (body) ->
387388
try

packages/server/test/unit/request_spec.coffee

+14
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,20 @@ describe "lib/request", ->
435435
.then (resp) ->
436436
expect(resp.body).to.deep.eq({status: "ok"})
437437

438+
it "parses response body as json if content-type application/vnd.api+json response headers", ->
439+
nock("http://localhost:8080")
440+
.get("/status.json")
441+
.reply(200, JSON.stringify({status: "ok"}), {
442+
"Content-Type": "application/vnd.api+json"
443+
})
444+
445+
request.sendPromise({}, @fn, {
446+
url: "http://localhost:8080/status.json"
447+
cookies: false
448+
})
449+
.then (resp) ->
450+
expect(resp.body).to.deep.eq({status: "ok"})
451+
438452
it "revives from parsing bad json", ->
439453
nock("http://localhost:8080")
440454
.get("/status.json")

0 commit comments

Comments
 (0)