lpar / gzipped

Replacement for golang http.FileServer which supports precompressed static assets.
BSD 3-Clause "New" or "Revised" License
94 stars 15 forks source link

Respect client Accept-Encoding quality values #2

Closed eklitzke closed 5 years ago

eklitzke commented 5 years ago

This change makes it so the gzipped library respects quality values when clients send them. Clients would now get a gzipped file rather than brotli encoded file (if possible) if they sent a header like:

Accept-Encoding: gzip;q=1, br;q=0.7

The other nice thing about this change is that header.ParseAccept() now only needs to be called one time; previously it was called twice, once for each encoding (brotli and gzip).

It should also now be a lot fewer lines of code to add new encodings support to this library. I considered adding deflate, but deflate is super old/deprecated and I don't know of any clients supporting deflate but not gzip, so I didn't see the point.

I added some new tests, and made the previous gzip tests table driven.

lpar commented 5 years ago

Thanks very much! Ironically I have a library for handling content negotiation headers which I haven't released yet, but it makes sense to handle the Accept-Encoding header without an external dependency.