Skip to content

Commit

Permalink
more permissive check for json to include application/vnd.api+j… (cyp…
Browse files Browse the repository at this point in the history
…ress-io#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
  • Loading branch information
jazwiecki authored and grabartley committed Oct 6, 2019
1 parent 27cecd4 commit 1f87fa5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/server/lib/request.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,8 @@ module.exports = (options = {}) ->

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

parseJsonBody: (body) ->
try
Expand Down
14 changes: 14 additions & 0 deletions packages/server/test/unit/request_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,20 @@ describe "lib/request", ->
.then (resp) ->
expect(resp.body).to.deep.eq({status: "ok"})

it "parses response body as json if content-type application/vnd.api+json response headers", ->
nock("http://localhost:8080")
.get("/status.json")
.reply(200, JSON.stringify({status: "ok"}), {
"Content-Type": "application/vnd.api+json"
})

request.sendPromise({}, @fn, {
url: "http://localhost:8080/status.json"
cookies: false
})
.then (resp) ->
expect(resp.body).to.deep.eq({status: "ok"})

it "revives from parsing bad json", ->
nock("http://localhost:8080")
.get("/status.json")
Expand Down

0 comments on commit 1f87fa5

Please sign in to comment.