Skip to content

Commit

Permalink
fix: cypress removes custom status text/reason phrase from http respo…
Browse files Browse the repository at this point in the history
…nse (#22061)
  • Loading branch information
kshastri committed Jun 16, 2022
1 parent d01932b commit 4319daa
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/proxy/lib/http/response-middleware.ts
Expand Up @@ -509,6 +509,12 @@ const MaybeSendRedirectToClient: ResponseMiddleware = function () {

const CopyResponseStatusCode: ResponseMiddleware = function () {
this.res.status(Number(this.incomingRes.statusCode))
// Set custom status message/reason phrase from http response
// https://github.com/cypress-io/cypress/issues/16973
if (this.incomingRes.statusMessage) {
this.res.statusMessage = this.incomingRes.statusMessage
}

this.next()
}

Expand Down
59 changes: 59 additions & 0 deletions packages/server/test/integration/http_requests_spec.js
Expand Up @@ -3783,6 +3783,65 @@ describe('Routes', () => {
})
})

// Set custom status message/reason phrase from http response
// https://github.com/cypress-io/cypress/issues/16973
it('set custom status message when reason phrase is set', function () {
nock(this.server.remoteStates.current().origin)
.post('/companies/validate', {
payload: { name: 'Brian' },
})
.reply(400, function (uri, requestBody) {
this.req.response.statusMessage = 'This is the custom status message'

return {
status: 400,
message: 'This is the reply body',
}
})

return this.rp({
method: 'POST',
url: 'http://localhost:8000/companies/validate',
json: true,
body: {
payload: { name: 'Brian' },
},
headers: {
'x-cypress-status': '400',
},
})
.then((res) => {
expect(res.statusCode).to.eq(400)
expect(res.statusMessage).to.eq('This is the custom status message')
})
})

// use default status message/reason phrase correspond to status code, from http response
// https://github.com/cypress-io/cypress/issues/16973
it('uses default status message when reason phrase is not set', function () {
nock(this.server.remoteStates.current().origin)
.post('/companies/validate', {
payload: { name: 'Brian' },
})
.reply(400)

return this.rp({
method: 'POST',
url: 'http://localhost:8000/companies/validate',
json: true,
body: {
payload: { name: 'Brian' },
},
headers: {
'x-cypress-status': '400',
},
})
.then((res) => {
expect(res.statusCode).to.eq(400)
expect(res.statusMessage).to.eq('Bad Request')
})
})

it('hands back 201 status codes', function () {
nock(this.server.remoteStates.current().origin)
.post('/companies/validate', {
Expand Down

5 comments on commit 4319daa

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 4319daa Jun 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.2.0/linux-x64/develop-4319daa7f4679dd4cf269c76055febcf304bd1d1/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 4319daa Jun 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.2.0/linux-arm64/develop-4319daa7f4679dd4cf269c76055febcf304bd1d1/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 4319daa Jun 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.2.0/darwin-arm64/develop-4319daa7f4679dd4cf269c76055febcf304bd1d1/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 4319daa Jun 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.2.0/darwin-x64/develop-4319daa7f4679dd4cf269c76055febcf304bd1d1/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 4319daa Jun 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.2.0/win32-x64/develop-4319daa7f4679dd4cf269c76055febcf304bd1d1/cypress.tgz

Please sign in to comment.