Skip to content

Commit b7a75a9

Browse files
authored
feat: add encoding even if .br/.gz specified (#923)
* Add handling of brotli/gzip pre-compressed files Serving pre-compressed brotli/gzip files was not working before, because a file.br.br against the pre-compressed file.br check always returned false. * Bump version from 14.1.1 to 14.1.2
1 parent 1d8972f commit b7a75a9

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/core/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ module.exports = function createMiddleware(_dir, _options) {
200200
path.relative(path.join('/', baseDir), pathname)
201201
)
202202
);
203-
// determine compressed forms if they were to exist
204-
gzippedFile = `${file}.gz`;
205-
brotliFile = `${file}.br`;
203+
// 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"
204+
gzippedFile = file.endsWith('gz') ? file : `${file}.gz`;
205+
brotliFile = file.endsWith('br') ? file : `${file}.br`;
206206

207207
Object.keys(headers).forEach((key) => {
208208
res.setHeader(key, headers[key]);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "http-server",
3-
"version": "14.1.1",
3+
"version": "14.1.2",
44
"description": "A simple zero-configuration command-line http server",
55
"main": "./lib/http-server",
66
"repository": {

0 commit comments

Comments
 (0)