-
-
Notifications
You must be signed in to change notification settings - Fork 241
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
base: master
Are you sure you want to change the base?
Conversation
It should use |
@bjohansebas @blakeembrey Is there a tentative date for merging this? |
@sardeeplakhera I hope it can be merged soon, although there’s still some time needed to ensure that everything works correctly. |
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? |
@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) |
@@ -48,6 +56,19 @@ var cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/ | |||
function compression (options) { | |||
var opts = options || {} | |||
|
|||
if (hasBrotliSupport) { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
8cd371f
to
013f9ce
Compare
Thank you the maintenance team! |
There was a problem hiding this 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.
@@ -48,6 +56,19 @@ var cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/ | |||
function compression (options) { | |||
var opts = options || {} | |||
|
|||
if (hasBrotliSupport) { |
There was a problem hiding this comment.
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.
Co-authored-by: Wes Todd <[email protected]>
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
The changes from #172 are brought in, with the exception of using the accept negotiation logic.