Skip to content

Commit 5c1efcf

Browse files
authored
fix: set status code 200 for empty responses (#1627)
1 parent cc5064c commit 5c1efcf

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

src/events/alb/HttpServer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,11 @@ export default class HttpServer {
313313
})
314314

315315
const hapiMethod = method === 'ANY' ? '*' : method
316-
const hapiOptions = {}
316+
const hapiOptions = {
317+
response: {
318+
emptyStatusCode: 200,
319+
},
320+
}
317321

318322
// skip HEAD routes as hapi will fail with 'Method name not allowed: HEAD ...'
319323
// for more details, check https://github.com/dherault/serverless-offline/issues/204

src/events/http/HttpServer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,9 @@ export default class HttpServer {
10451045
const hapiOptions = {
10461046
auth: authStrategyName,
10471047
cors,
1048+
response: {
1049+
emptyStatusCode: 200,
1050+
},
10481051
state,
10491052
timeout: {
10501053
socket: false,

tests/integration/alb-handler/handlerPayload.test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,16 @@ describe('ALB handler payload tests', function desc() {
9999

100100
{
101101
description:
102-
'when handler returns bad answer in promise should return 204',
102+
'when handler returns bad answer in promise should return 200',
103103
path: '/dev/bad-answer-in-promise-handler',
104-
status: 204,
104+
status: 200,
105105
},
106106

107107
{
108108
description:
109-
'when handler returns bad answer in callback should return 204',
109+
'when handler returns bad answer in callback should return 200',
110110
path: '/dev/bad-answer-in-callback-handler',
111-
status: 204,
111+
status: 200,
112112
},
113113

114114
{
@@ -121,7 +121,7 @@ describe('ALB handler payload tests', function desc() {
121121
{
122122
description: 'test path with wildcards',
123123
path: '/dev/foo/test-resource-variable-handler/1',
124-
status: 204,
124+
status: 200,
125125
},
126126

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

269269
{
270270
description:
271-
'when handler returns bad answer in promise should return 204',
271+
'when handler returns bad answer in promise should return 200',
272272
path: '/bad-answer-in-promise-handler',
273-
status: 204,
273+
status: 200,
274274
},
275275

276276
{
277277
description:
278-
'when handler returns bad answer in callback should return 204',
278+
'when handler returns bad answer in callback should return 200',
279279
path: '/bad-answer-in-callback-handler',
280-
status: 204,
280+
status: 200,
281281
},
282282

283283
{
@@ -290,7 +290,7 @@ describe('ALB handler payload tests with prepend off', function desc() {
290290
{
291291
description: 'test path with wildcards',
292292
path: '/foo/test-resource-variable-handler/1',
293-
status: 204,
293+
status: 200,
294294
},
295295

296296
{

tests/integration/handler/handlerPayload.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,16 @@ describe('handler payload tests', function desc() {
115115

116116
{
117117
description:
118-
'when handler returns bad answer in promise should return 204',
118+
'when handler returns bad answer in promise should return 200',
119119
path: '/dev/bad-answer-in-promise-handler',
120-
status: 204,
120+
status: 200,
121121
},
122122

123123
{
124124
description:
125-
'when handler returns bad answer in callback should return 204',
125+
'when handler returns bad answer in callback should return 200',
126126
path: '/dev/bad-answer-in-callback-handler',
127-
status: 204,
127+
status: 200,
128128
},
129129

130130
{
@@ -283,16 +283,16 @@ describe('handler payload tests with prepend off', function desc() {
283283

284284
{
285285
description:
286-
'when handler returns bad answer in promise should return 204',
286+
'when handler returns bad answer in promise should return 200',
287287
path: '/bad-answer-in-promise-handler',
288-
status: 204,
288+
status: 200,
289289
},
290290

291291
{
292292
description:
293-
'when handler returns bad answer in callback should return 204',
293+
'when handler returns bad answer in callback should return 200',
294294
path: '/bad-answer-in-callback-handler',
295-
status: 204,
295+
status: 200,
296296
},
297297

298298
{

tests/old-unit/offline.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ describe('Offline', () => {
852852

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

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

@@ -914,7 +914,7 @@ describe('Offline', () => {
914914
url: '/dev/cookie',
915915
})
916916

917-
assert.strictEqual(res.statusCode, 204)
917+
assert.strictEqual(res.statusCode, 200)
918918

919919
await offline.end(true)
920920
})
@@ -1108,7 +1108,7 @@ describe('Offline', () => {
11081108
url: '/dev/cookie',
11091109
})
11101110

1111-
assert.strictEqual(res.statusCode, 204)
1111+
assert.strictEqual(res.statusCode, 200)
11121112

11131113
await offline.end(true)
11141114
})

0 commit comments

Comments
 (0)