Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index overflow #99

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added test/fixtures/br.json.gz
Binary file not shown.
1 change: 1 addition & 0 deletions test/fixtures/index.html/index
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
text index
1 change: 1 addition & 0 deletions test/fixtures/world/world
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
html index
43 changes: 43 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,34 @@ describe('send(ctx, file)', function () {
.expect('html index', done)
})
})

describe('when the index file is not present', function () {
it('should 404 if the index is a directory', function (done) {
const app = new Koa()

app.use(async (ctx) => {
const opts = { root: 'test', index: 'index', extensions:['html', 'htm'] }
await send(ctx, 'fixtures/', opts)
})

request(app.listen())
.get('/')
.expect(404, done)
})

it('should 404 if the index is a directory', function (done) {
const app = new Koa()

app.use(async (ctx) => {
const opts = { root: 'test', index: 'world' }
await send(ctx, 'fixtures/', opts)
})

request(app.listen())
.get('/')
.expect(404, done)
})
})
})

describe('when path is not a file', function () {
Expand Down Expand Up @@ -467,6 +495,21 @@ describe('send(ctx, file)', function () {
.expect('{ "name": "tobi" }')
.expect(200, done)
})

it('should return .gz path when brotli is unavailable', function (done) {
const app = new Koa()

app.use(async (ctx) => {
await send(ctx, '/test/fixtures/br.json')
})

request(app.listen())
.get('/')
.set('Accept-Encoding', 'br, gzip, deflate, identity')
.expect('Content-Length', '48')
.expect('{ "name": "tobi" }')
.expect(200, done)
})
})

describe('and max age is specified', function () {
Expand Down