jshttp / negotiator

An HTTP content negotiator for Node.js
MIT License
320 stars 36 forks source link

Added an option preferred encodings array #59

Closed danielgindi closed 3 months ago

danielgindi commented 3 years ago

Will be used in https://github.com/expressjs/compression/pull/172

danielgindi commented 3 years ago

@dougwilson Would you mind adding a minor change to accepts if/when this PR is merged? This will save some time. Then I'll revert the brotli branch to use accepts module with a simple extra argument.

nicksrandall commented 3 years ago

@dougwilson thanks for shepherding this along.

wesleytodd commented 3 months ago

After merging this I was looking at the api and realized we are limiting ourselves by passing an array directly, so I wrapped it in an options object so we have less of a chance of needing to break that api in future changes. That is what I will release with 1.0.

bjohansebas commented 1 month ago

@blakeembrey This PR can be backported to version 0; it is necessary for express/compression to have this feature in order to correctly handle the request encodings and thus add Brotli support

blakeembrey commented 1 month ago

@bjohansebas any reason compression can’t be bumped to 1.0 and do its own major release for the feature?

bjohansebas commented 1 month ago

jshttp/negotiator and jshttp/accepts removed support for Node.js <18. express/compression has support for older versions, and since it's a widely used package in the ecosystem, I don’t think it’s best to remove support for older versions and not be able to provide the feature that has been awaited for years in that package (Brotli support) in the current major version.

blakeembrey commented 1 month ago

While I agree generally, I’d recommend bumping the major version and minimum node version for compression. It’s not as big a deal as you might expect, since there’s no other breaking changes except node version support, and would allow you to avoid feature flagging brotli support since it only exists around node v12.

Since you aren’t breaking any other features, people can freely upgrade to v2 if they’re using a newer node version. I don’t think it’ll be an issue for people who want brotli support to be using a supported node version.

blakeembrey commented 1 month ago

OK, I just checked out master from this merge commit and released that directly as 0.6.4. Does that work for you?

bjohansebas commented 1 month ago

It's working well, although we need to integrate this option into jshttp/accepts so we don't have to bring its logic into compression and can use it directly.