Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more permissive check for json to include application/vnd.api+j… #5166

Merged
merged 4 commits into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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