Skip to content

Support serving pre-compressed files for static sites#2615

Merged
JohnTitor merged 7 commits intoactix:mainfrom
antonok-edm:static-compression
Feb 8, 2026
Merged

Support serving pre-compressed files for static sites#2615
JohnTitor merged 7 commits intoactix:mainfrom
antonok-edm:static-compression

Conversation

@antonok-edm
Copy link
Copy Markdown
Contributor

@antonok-edm antonok-edm commented Jan 28, 2022

PR Type

Feature

PR Checklist

  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • A changelog entry has been made for the appropriate packages.
  • Format code with the latest stable rustfmt.
  • (Team) Label with affected crates and semver status.

Overview

This PR adds the Files::try_compressed() builder method. If a static files service is constructed with that method, each incoming request will automatically check for a pre-compressed .gz, .br, or .zst file on disk, in order of preference according to the Accept-Encoding header, before falling back to the normal uncompressed file. When a compressed file is selected, the Content-Encoding header is populated with the respective compression type, while the Content-Type and Content-Disposition fields retain the original file's values.

There should be no breaking changes here, although I've had to expose some fields in ways that may not be ideal (I'm looking at the SUPPORTED_ENCODINGS list in particular, and perhaps the new features I've copied straight from actix-web - let me know if you have a better idea of how to structure any of that!). Resolved, see #2615 (comment)

Closes #2415

@robjtede robjtede added this to the actix-web post-v4 milestone Jan 28, 2022
@robjtede robjtede added A-files project: actix-files B-semver-minor labels Jan 28, 2022
@antonok-edm
Copy link
Copy Markdown
Contributor Author

After some reflection, I've realized there's no reason to tie the supported precompression formats here to the supported runtime compression formats in actix-web, since these ones don't actually depend on any additional dependencies. That means there's no need to reference the SUPPORTED_ENCODINGS from actix-web, and no need to have additional features exposed, and it makes things overall a bit neater.

I've pushed those changes.

@robjtede robjtede removed this from the actix-web post-v4 milestone Mar 1, 2022
@lilnasy
Copy link
Copy Markdown

lilnasy commented Mar 26, 2023

@robjtede miniserve depends on actix-files and would really benefit from this PR merging. Is there something blocking its review?

@robjtede
Copy link
Copy Markdown
Member

Just time allocation. Reviews from interested parties will help massively.

Copy link
Copy Markdown
Member

@JohnTitor JohnTitor left a comment

Choose a reason for hiding this comment

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

Thank you for the PR and sorry for the delay!
LGTM with some tweaks.

@JohnTitor JohnTitor added this pull request to the merge queue Feb 8, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Feb 8, 2026
@JohnTitor JohnTitor added this pull request to the merge queue Feb 8, 2026
@JohnTitor JohnTitor removed this pull request from the merge queue due to a manual request Feb 8, 2026
@JohnTitor JohnTitor added this pull request to the merge queue Feb 8, 2026
Merged via the queue into actix:main with commit 9856a3b Feb 8, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-files project: actix-files B-semver-minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

static compression feature for actix-files

4 participants