Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Commit

Permalink
fix: always require next call (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
boywithkeyboard authored Jul 19, 2023
1 parent 400e23d commit a4e726d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cheetah.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,14 @@ export class cheetah extends base<cheetah>() {

const len = handlers.length

let next = false
let next = true

for (let i = 0; i < len; ++i) {
if (typeof handlers[i] !== 'function') {
continue
}

if ($.b && !next) {
if (!next) {
break
}

Expand Down
30 changes: 27 additions & 3 deletions test/many_handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import cheetah from '../mod.ts'
Deno.test('Many Handlers', async () => {
const app = new cheetah()

app.get('/test', (_, next) => {
app.get('/a', (_, next) => {
next()

return 'a'
Expand All @@ -15,15 +15,39 @@ Deno.test('Many Handlers', async () => {
}
})

app.get('/b', (c) => {
c.res.header('foo', 'bar')
}, (c) => {
c.res.header('foo', 'foo')
})

app.get('/c', (c, next) => {
c.res.header('foo', 'bar')

next()
}, (c) => {
c.res.header('foo', 'foo')
})

assertEquals(
await (await app.fetch(new Request('http://localhost/test'))).text(),
await (await app.fetch(new Request('http://localhost/a'))).text(),
'a',
)

assertEquals(
await (await app.fetch(
new Request('http://localhost/test', { headers: { 'foo': 'bar' } }),
new Request('http://localhost/a', { headers: { 'foo': 'bar' } }),
)).text(),
'b',
)

assertEquals(
(await app.fetch(new Request('http://localhost/b'))).headers.get('foo'),
'bar',
)

assertEquals(
(await app.fetch(new Request('http://localhost/c'))).headers.get('foo'),
'foo',
)
})

0 comments on commit a4e726d

Please sign in to comment.