Skip to content

Commit

Permalink
fix(Context): c.body() accept null for 204 response (#245)
Browse files Browse the repository at this point in the history
Fix #242
  • Loading branch information
yusukebe authored May 18, 2022
1 parent 9c3eb27 commit 600847b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ describe('Context', () => {
expect(res.statusText).toBe('OK')
})

it('Should return 204 response', async () => {
c.status(204)
const res = c.body(null)
expect(res.status).toBe(204)
expect(res.statusText).toBe('No Content')
expect(await res.text()).toBe('')
})

it('Should be able read env', async () => {
const req = new Request('http://localhost/')
const key = 'a-secret-key'
Expand Down
6 changes: 5 additions & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ export class Context<RequestParamKeyType extends string = string, E = Env> {
return new Response(data, init)
}

body(data: Data, status: StatusCode = this._status, headers: Headers = this._headers): Response {
body(
data: Data | null,
status: StatusCode = this._status,
headers: Headers = this._headers
): Response {
return this.newResponse(data, {
status: status,
headers: headers,
Expand Down

0 comments on commit 600847b

Please sign in to comment.