Skip to content

Conversation

azeitler
Copy link
Contributor

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.

Relevant issues

Adresses Fails to serve Unity/Brotli #844

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.
Copy link
Contributor

@KernelDeimos KernelDeimos left a comment

Choose a reason for hiding this comment

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

This works but it has a consequence - we can no longer directly download the archive. In some situations this might be desirable; it's kind of cool that we have the ability to both preview compressed files as well as download them.

The best thing would be to have the directory listing page provide both options. Clicking the filename should "preview" (i.e. navigate to ./test.jpeg, not ./test.jpeg.br) rather than download, and perhaps a download icon could navigate to ./test.jpeg.br.

This behavior might be desirable sometimes too, but it should be behind a flag because technically it's a regression. I'm going to create a new active branch called better-brotli and merge this there.

Comment on lines +204 to +205
gzippedFile = file.endsWith('gz') ? file : `${file}.gz`;
brotliFile = file.endsWith('br') ? file : `${file}.br`;
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`;

@KernelDeimos KernelDeimos changed the base branch from master to better-brotli September 22, 2025 19:28
@KernelDeimos KernelDeimos merged commit b7a75a9 into http-party:better-brotli Sep 22, 2025
KernelDeimos added a commit that referenced this pull request Sep 26, 2025
* 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

* fix: always check the dot

This fixes an issue recently introduced where file extensions ending
with `br` are handled even when the dot does not immediately
preceded. This introduces erroneous an error when trying to access
files with other extensions ending with `br`, such as `.cbr`.

I meant to merge the previous PR with this fix included but forgot to
commit the suggestion I added in the PR review. This was merged to a
feature branch so the main branch was not affected.

* fix: put new behavior for .br/.gz behind a flag

Adds --force-content-encoding flag which must be specified to enable
the behavior of including the Content-Encoding header in the response
when a .br or .gz file is directly requested in the URL.

* test: --force-content-encoding flag

Tests whether or not Content-Encoding is present under different cases
with and without the --force-content-encoding flag set.

* doc: update manpage

* sync: package-lock.json

---------

Co-authored-by: Andreas Zeitler <[email protected]>
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.

2 participants