-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
fix: default brotliOptions does not applied to createBrotliCompress and createBrotliDecompress #284
fix: default brotliOptions does not applied to createBrotliCompress and createBrotliDecompress #284
Conversation
…nd createBrotliDecompress
2ed62ac
to
ff2f873
Compare
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.
lgtm
There is a type error... can you take a look? |
…ic compress will be merged with global options anyway)
@gurgunday I tried to understand the error, but have no clue why it is failed. It expects to throw an type error for |
After some more code reading, I made a follow-up change. The compress level will be set to 4 for the global option only. If route has its own compression options, it will be merged with global options anway. No need to double overwrite. |
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.
Lgtm. but for some reasons our types tests are failing.
(This can’t land otherwise, and it seems not independent).
I'm thinking if https://github.com/fastify/fastify-compress/blob/master/types/index.test-d.ts#L101-L112 is needed. I'm prefer to remove them |
Can you try this? appWithoutGlobal.inject(
{
method: 'GET',
path: '/throw-a-ts-arg-error',
headers: {
'accept-encoding': 'gzip'
}
},
(err) => {
expectType<Error | undefined>(err) // add undefined
}
) |
@gurgunday @mcollina by changing |
Yeah seems like ts(d) behavior changed I will release a new version of this package |
Indeed. It's an interesting test error. Thank you both for reviewing the code change. This project is quite well coded and documented. I'm glad that I contributed some bugfix for it.👍 |
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.
lgtm
The problem
I encounted a remarkable performance slow down after migrating from Koa.
Although the doc mentions fastify/compress already sets the compression level to 4, but it takes too long to compress (3MB for 5 sec) a json. I guess it is configured unexpectedly by default.
After some investigation, it could be related to the previous merge request #278.
Unless I explicitly set the compression level to
4
, I will get11
(BROTLI_DEFAULT_QUALITY).The root cause
The compression level is a member of
brotliOptions.params
notbrotliOptions
. https://nodejs.org/api/zlib.html#class-brotlioptionsAnd unfortunately the global default option is overwritten by custom option afterwards https://github.com/fastify/fastify-compress/blob/master/index.js#L129
The change
4
.8
and check if it is compressed expectedly.Loop in author of previous commit @kahlstrm as well.
Checklist
npm run test
andnpm run benchmark
and the Code of conduct