tower-http
tower-http copied to clipboard
Compression encoding preference
Feature Request
Motivation
Currently, when using Firefox for example, the encoding used by CompressionLayer is GZIP, which is unfortunate, considering that Brotli produces far smaller files and Firefox does support it.
Proposal
Currently the encoding used by CompressionLayer, is the first one listed in Accept-Encoding, which, as far as I can tell, is not mandated by the specification, see RFC 9110 Section 12.5.3 and 8.4.1.
Furthermore, most servers don't handle it this way and just pick the one from the list they prefer the most. When clients want to specify which one they prefer, they have to use quality values, which is already supported by CompressionLayer (as far as I can tell).
So my proposal is:
- Specify a default server preference for each encoding instead of picking the first one.
- Expose an interface to let the user specify a preference.
Happy to make a PR of course.
Alternatives
For example, if Brotli is the encoding preferred, users could always just only enable that crate feature, considering Brotli is widely supported. Obviously this isn't ideal.
Otherwise implementing CompressionLayer by hand always works.
Adding a method for specifying the preferred compression (if the client doesn't have a preference) sounds good to me!