Skip to content

Commit

Permalink
fix: set status code 200 for empty responses (#1627)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk authored Dec 12, 2022
1 parent cc5064c commit 5c1efcf
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 22 deletions.
6 changes: 5 additions & 1 deletion src/events/alb/HttpServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,11 @@ export default class HttpServer {
})

const hapiMethod = method === 'ANY' ? '*' : method
const hapiOptions = {}
const hapiOptions = {
response: {
emptyStatusCode: 200,
},
}

// skip HEAD routes as hapi will fail with 'Method name not allowed: HEAD ...'
// for more details, check https://github.com/dherault/serverless-offline/issues/204
Expand Down
3 changes: 3 additions & 0 deletions src/events/http/HttpServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,9 @@ export default class HttpServer {
const hapiOptions = {
auth: authStrategyName,
cors,
response: {
emptyStatusCode: 200,
},
state,
timeout: {
socket: false,
Expand Down
20 changes: 10 additions & 10 deletions tests/integration/alb-handler/handlerPayload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,16 @@ describe('ALB handler payload tests', function desc() {

{
description:
'when handler returns bad answer in promise should return 204',
'when handler returns bad answer in promise should return 200',
path: '/dev/bad-answer-in-promise-handler',
status: 204,
status: 200,
},

{
description:
'when handler returns bad answer in callback should return 204',
'when handler returns bad answer in callback should return 200',
path: '/dev/bad-answer-in-callback-handler',
status: 204,
status: 200,
},

{
Expand All @@ -121,7 +121,7 @@ describe('ALB handler payload tests', function desc() {
{
description: 'test path with wildcards',
path: '/dev/foo/test-resource-variable-handler/1',
status: 204,
status: 200,
},

{
Expand Down Expand Up @@ -268,16 +268,16 @@ describe('ALB handler payload tests with prepend off', function desc() {

{
description:
'when handler returns bad answer in promise should return 204',
'when handler returns bad answer in promise should return 200',
path: '/bad-answer-in-promise-handler',
status: 204,
status: 200,
},

{
description:
'when handler returns bad answer in callback should return 204',
'when handler returns bad answer in callback should return 200',
path: '/bad-answer-in-callback-handler',
status: 204,
status: 200,
},

{
Expand All @@ -290,7 +290,7 @@ describe('ALB handler payload tests with prepend off', function desc() {
{
description: 'test path with wildcards',
path: '/foo/test-resource-variable-handler/1',
status: 204,
status: 200,
},

{
Expand Down
16 changes: 8 additions & 8 deletions tests/integration/handler/handlerPayload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ describe('handler payload tests', function desc() {

{
description:
'when handler returns bad answer in promise should return 204',
'when handler returns bad answer in promise should return 200',
path: '/dev/bad-answer-in-promise-handler',
status: 204,
status: 200,
},

{
description:
'when handler returns bad answer in callback should return 204',
'when handler returns bad answer in callback should return 200',
path: '/dev/bad-answer-in-callback-handler',
status: 204,
status: 200,
},

{
Expand Down Expand Up @@ -283,16 +283,16 @@ describe('handler payload tests with prepend off', function desc() {

{
description:
'when handler returns bad answer in promise should return 204',
'when handler returns bad answer in promise should return 200',
path: '/bad-answer-in-promise-handler',
status: 204,
status: 200,
},

{
description:
'when handler returns bad answer in callback should return 204',
'when handler returns bad answer in callback should return 200',
path: '/bad-answer-in-callback-handler',
status: 204,
status: 200,
},

{
Expand Down
6 changes: 3 additions & 3 deletions tests/old-unit/offline.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ describe('Offline', () => {

const res = await server.inject('/dev/headers')

assert.strictEqual(res.statusCode, 204)
assert.strictEqual(res.statusCode, 200)
assert.strictEqual(res.headers['custom-header-1'], undefined)
assert.strictEqual(res.headers['custom-header-2'], undefined)

Expand Down Expand Up @@ -914,7 +914,7 @@ describe('Offline', () => {
url: '/dev/cookie',
})

assert.strictEqual(res.statusCode, 204)
assert.strictEqual(res.statusCode, 200)

await offline.end(true)
})
Expand Down Expand Up @@ -1108,7 +1108,7 @@ describe('Offline', () => {
url: '/dev/cookie',
})

assert.strictEqual(res.statusCode, 204)
assert.strictEqual(res.statusCode, 200)

await offline.end(true)
})
Expand Down

0 comments on commit 5c1efcf

Please sign in to comment.