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: support for brotli #194

Open
wants to merge 32 commits into
base: master
Choose a base branch
from

Conversation

bjohansebas
Copy link
Member

@bjohansebas bjohansebas commented Oct 19, 2024

The changes from #172 are brought in, with the exception of using the accept negotiation logic.

@bjohansebas
Copy link
Member Author

It should use accepts, so this PR is not ready yet, and I don't have the option to turn it into a draft. I will soon open a PR in accepts to be able to use this logic

@bjohansebas bjohansebas self-assigned this Oct 19, 2024
@UlisesGascon UlisesGascon requested a review from a team October 20, 2024 17:24
@bjohansebas bjohansebas marked this pull request as draft October 22, 2024 21:07
encoding_negotiator.js Outdated Show resolved Hide resolved
@bjohansebas bjohansebas marked this pull request as ready for review October 24, 2024 00:17
encoding_negotiator.js Outdated Show resolved Hide resolved
encoding_negotiator.js Outdated Show resolved Hide resolved
encoding_negotiator.js Outdated Show resolved Hide resolved
@sardeeplakhera
Copy link

@bjohansebas @blakeembrey Is there a tentative date for merging this?

@bjohansebas
Copy link
Member Author

@sardeeplakhera I hope it can be merged soon, although there’s still some time needed to ensure that everything works correctly.

@sardeeplakhera
Copy link

Thanks, @bjohansebas! Do you think first week of December could be a realistic target for the release? Or is there anything else that might push it back further?

@bjohansebas
Copy link
Member Author

@sardeeplakhera i think a new patch version for this package could be ready by December. Currently, this work is more like a proposal for version 1.8.0 (see #189)

test/compression.js Outdated Show resolved Hide resolved
@@ -48,6 +56,19 @@ var cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/
function compression (options) {
var opts = options || {}

if (hasBrotliSupport) {
Copy link
Member

Choose a reason for hiding this comment

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

It may be a good opportunity to stop passing through opts blindly to each method and instead define it as brotliParams?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think in this case it makes sense to assign it this way, since the options for each compression method have not been separated yet, or maybe I misunderstood your idea.

https://nodejs.org/api/zlib.html#class-brotlioptions

Copy link
Member

Choose a reason for hiding this comment

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

I think if we follow this suggestion it would also remove the need for the objectAssign addition right? because we could just manually enumerate the options for each compression method.

Copy link
Member Author

Choose a reason for hiding this comment

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

If I'm understanding the idea correctly, the function would look something like this:

function compression (options) {
  var gzipOptions = {
    level: opts.level,
    memLevel: opts.memLevel,
    strategy: opts.strategy
  }

  var brotliOptions = {
    level: opts.level,
    memLevel: opts.memLevel,
    strategy: opts.strategy
    params: opts.brotliParams
  }
//...

  stream = method === 'gzip'
        ? zlib.createGzip(gzipOptions)
        : method === 'br'
          ? zlib.createBrotliCompress(brotliOptions)
          : zlib.createDeflate(gzipOptions)

Copy link
Member

Choose a reason for hiding this comment

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

Don't create the objects unless you are going to use them, but yes in general this is what I was thinking.

Copy link
Member Author

Choose a reason for hiding this comment

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

@wesleytodd, enumerating the options doesn't seem like a good idea to me, as it adds unnecessary maintenance to the package. I think adding the Brotli option separately should be sufficient for now.

index.js Outdated Show resolved Hide resolved
@Fonger
Copy link

Fonger commented Oct 26, 2024

Thank you the maintenance team!
Glad to see it finally gets some progress.

Copy link
Member

@wesleytodd wesleytodd left a comment

Choose a reason for hiding this comment

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

I am leaving this as "request changes" because I think we need to spend a bit more time to decide what changes should be landed from the comments before merging. That said, I don't actually consider any of my comments as blocking. If we get answers on the comments then ping me or just merge without more review from me.

package.json Show resolved Hide resolved
test/compression.js Outdated Show resolved Hide resolved
@@ -48,6 +56,19 @@ var cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/
function compression (options) {
var opts = options || {}

if (hasBrotliSupport) {
Copy link
Member

Choose a reason for hiding this comment

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

I think if we follow this suggestion it would also remove the need for the objectAssign addition right? because we could just manually enumerate the options for each compression method.

index.js Show resolved Hide resolved
@bjohansebas
Copy link
Member Author

hi @wesleytodd @blakeembrey, I've updated the options to avoid using object-assign, would love to hear your feedback

}

if (optsBrotli.params[zlib.constants.BROTLI_PARAM_QUALITY] === undefined) {
optsBrotli.params[zlib.constants.BROTLI_PARAM_QUALITY] = 4
Copy link
Member

Choose a reason for hiding this comment

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

I think this was better when using object-assign, now we would be mutating user input if it exists.

I also think optsBrotli is only a marginally better change, I'd probably do something more like this (if you want to go down this route):

var brotliOptions = {
  [zlib.constants.BROTLI_PARAM_QUALITY]: opts.brotliQuality,
};

I.e. the nesting of brotli: { quality: 4 } also seems reasonable, my main concern was that passing through as-is some of those option may actually interfere with the package working (like flush maybe?). I'm not too familiar with this, so trust your judgement on this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will use Object.assign again to avoid directly mutating the object. Also, I prefer that developers pass the options directly, as it was done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants