Skip to content
Merged
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
6 changes: 3 additions & 3 deletions lib/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ module.exports = function createMiddleware(_dir, _options) {
path.relative(path.join('/', baseDir), pathname)
)
);
// determine compressed forms if they were to exist
gzippedFile = `${file}.gz`;
brotliFile = `${file}.br`;
// determine compressed forms if they were to exist, make sure to handle pre-compressed files, i.e. files with .br/.gz extension. we will serve them "as-is"
gzippedFile = file.endsWith('gz') ? file : `${file}.gz`;
brotliFile = file.endsWith('br') ? file : `${file}.br`;
Comment on lines +204 to +205
Copy link
Contributor

Choose a reason for hiding this comment

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

Careful! We need to check for the dot (.) in the file extension too. A common format for comicbook archives (.cbr) also passes .endsWith('br') and would be sent with the header for brotli encoding. I tested this myself and it results in an error in my browser.

Suggested change
gzippedFile = file.endsWith('gz') ? file : `${file}.gz`;
brotliFile = file.endsWith('br') ? file : `${file}.br`;
gzippedFile = file.endsWith('.gz') ? file : `${file}.gz`;
brotliFile = file.endsWith('.br') ? file : `${file}.br`;


Object.keys(headers).forEach((key) => {
res.setHeader(key, headers[key]);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "http-server",
"version": "14.1.1",
"version": "14.1.2",
"description": "A simple zero-configuration command-line http server",
"main": "./lib/http-server",
"repository": {
Expand Down