Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add brotli support #156

Closed
wants to merge 20 commits into from
Closed

feat: add brotli support #156

wants to merge 20 commits into from

Conversation

patrickmichalina
Copy link

@patrickmichalina patrickmichalina commented May 31, 2019

createBrotliDecompress and createBrotliCompress are only available in Node v10.16.0 and above. If the platform you are running supports brotli and the client making a request accepts brotli encoding, this will return brotli encoded responses, otherwise it will fallback as before.

Added a config option brotli.

compression({
  ...,
  brotli: {
    enabled: false,
    zlib: { ... } // https://nodejs.org/api/zlib.html#zlib_class_brotlioptions
  }
})

@ghostganz
Copy link

Node 10.16.0 (LTS) now has Brotli support too.

@curbengh
Copy link

curbengh commented Jul 6, 2019

I think iltorb library is a better option for now, to be compatible with Node 8. Once Node 8 has reached EOL (planned 2019-12-31), then it can be replaced with native's.

Edit: #158 uses both zlib and iltorb.

@benwiggins
Copy link

Introducing a dependency that requires pre-compiled binaries and/or a gcc and python 2.7 toolchain just to bring a new feature to a non-active LTS branch that will be dead in 6 months doesn't seem "better" to me.

Node 8 is in maintenance, let it remain that way with the existing compression feature set.

README.md Outdated Show resolved Hide resolved
@xquelard
Copy link

xquelard commented Sep 9, 2019

Is there anything missing in this PR to be merged?

@dougwilson
Copy link
Contributor

#71 (comment)

@garthenweb
Copy link

@dougwilson To sum this up, a proper implementation for the options and it's documentation is missing here, correct? Test vise this PR looks already good to me (tests for options would be nice as well as soon as this is implemented).

So, regarding the options here some documentation.
BrotliOptions: https://nodejs.org/api/zlib.html#zlib_class_brotlioptions
ZlipOptions: https://nodejs.org/api/zlib.html#zlib_class_options

The only option that looks interchangeable to me is chunkSize. flush and finishFlush have the same name on both methods but they use different constants, so the meaning is probably not the same.
What would be the best option here? Should we maybe change the options completely so that we can separate brotli and zlib options from each other? Like

app.use(compression({
  filter: shouldCompress,
  brotli: {
    flush: zlib.constants.BROTLI_OPERATION_PROCESS,
    params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 4 },
    ...
  },
  zlib: {
    flush: zlib.constants.Z_NO_FLUSH,
    memLevel: zlib.Z_DEFAULT_MEMLEVEL,
    ...
  }
}))

This would require a breaking change, but I would argue that adding this option is a breaking change anyhow if it should be activated by default (which I would prefer) and it would not be to hard to migrate.

What is your opinion on this? Am I missing a requirement from the comments in the other PR's/ issues?

I would love to get this into the library as it would hopefully have a positive effect on a lot of websites, and the PR already looks solid ❤️

@patrickmichalina
Copy link
Author

@dougwilson struggling to reach 100% coverage with node environments that do not support brotli.

@gengjiawen
Copy link

@dougwilson Can you take another look ?

@KB1RMA
Copy link

KB1RMA commented Mar 24, 2020

Is this still being held up by being not being able to hit 100% coverage? Seems a shame for such a small yet great change which could make a big difference in a large number of sites!

@ryhinchey
Copy link

Is this still being held up by being not being able to hit 100% coverage? Seems a shame for such a small yet great change which could make a big difference in a large number of sites!

@KB1RMA I believe the biggest issue is confirming that a major version could be released for this. The existing api needs to change to add brotli support. See here #156 (comment)

@dougwilson are you open to releasing a new major version to this module with an updated api that will let people specify separate options for brotli and gzip?

@patrickmichalina
Copy link
Author

patrickmichalina commented Mar 26, 2020

@ryhinchey this PR actually breaks out brotli vs gzip settings. But a major version bump does make sense IMO.

compression({
  ...,
  brotli: {
    enabled: false, // default to false, unchanged behavior with current version
    zlib: { ... } // https://nodejs.org/api/zlib.html#zlib_class_brotlioptions
  }
})

Node environments without the new brotli feature are unable to execute a branch of code so the code coverage never reaches 100%. Anyway to work around this for that section of code?

Screen Shot 2020-03-25 at 9 49 26 PM

@adityapatadia

This comment has been minimized.

@dougwilson

This comment has been minimized.

@kubmir

This comment has been minimized.

@dougwilson

This comment has been minimized.

@KB1RMA

This comment has been minimized.

@dougwilson

This comment has been minimized.

@expressjs expressjs locked as too heated and limited conversation to collaborators Apr 17, 2020
@patrickmichalina patrickmichalina marked this pull request as draft September 7, 2021 14:03
@patrickmichalina patrickmichalina marked this pull request as ready for review September 7, 2021 14:03
@bjohansebas
Copy link
Member

Closed in favor of #194, @patrickmichalina thank you for the initiative. You can continue helping by reviewing #194 so we can launch it.

@bjohansebas bjohansebas closed this Nov 3, 2024
@expressjs expressjs unlocked this conversation Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.