fix: prevents fastify-compress from trying to work with something it cannot#361
Open
Aeolun wants to merge 2 commits intofastify:mainfrom
Open
fix: prevents fastify-compress from trying to work with something it cannot#361Aeolun wants to merge 2 commits intofastify:mainfrom
Aeolun wants to merge 2 commits intofastify:mainfrom
Conversation
mcollina
requested changes
Jun 17, 2025
Member
mcollina
left a comment
There was a problem hiding this comment.
Thanks for opening a PR! Can you please add a unit test?
…cannot Sending something other than buffers of strings in the `payload` happens, but this would break the later `Buffer.byteLength(payload)` Signed-off-by: Bart Riepe <bart@serial-experiments.com>
Member
|
Great work! Can you document this new option? |
This comment was marked as spam.
This comment was marked as spam.
Member
|
@Aeolun yes. There is a new option passed as the config of the plugin, and that should be mentioned in the README.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I'm still trying to figure out how it happens (something involving tRPC responses), but for now I'll be happy if I can stop compress from trying to compress something it can't.
I assume the differing behavior between the automatic compression (hook), and manual compression (the
compressfunction) is because you don't want to mess with payloads (e.g. serialize them) unless people explicitly call the compress function. I've kept that behavior, and the global hook simply doesn't compress if it gets something it cannot deal with, while the compress function, well, it already serialized things, so it might cause wonky behavior if you pass it a Response object.Tests:
Responseobjects are not compressed on global hookcompressResponseobjects are compressed after being serialized to{}with thecompressfunction.Checklist
npm run testandnpm run benchmarkand the Code of conduct