Skip to content

Conversation

@disintegrator
Copy link
Contributor

@disintegrator disintegrator commented Nov 18, 2019

Currently, when fastify-static is configured with redirect option set to false and a request for a directory does not contain a trailing slash, it causes the server to hang. This is because we only register a directory handler on the underlying send stream if redirect option is true.

This PR updates the library to handle such requests by calling reply.callNotFound(). We presume that requesting a directory without using a trailing slash OR setting redirect to true should be handled explicitly as a 404.

To reproduce the bug:

const path = require('path')
const Fastify = require('fastify')
const fastifyStatic = require('fastify-static')

const fastify = Fastify()
fastify.register(fastifyStatic, {
  // using the fixture in fastify-static's test folder
  root: path.join(__dirname, '/test/static'),
  redirect: false
})

fastify.listen(3000, () => {
  console.log('ready')
})

In another terminal, running the following command will hang indefinitely:

curl http://localhost:3000/deep/path/for/test

Checklist

  • run npm run test and npm run benchmark
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message and code follows Code of conduct

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, good work

@mcollina mcollina requested review from Eomm and delvedor November 18, 2019 07:29
Copy link
Member

@delvedor delvedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Copy link
Member

@RafaelGSS RafaelGSS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants