fastify-compress
fastify-compress copied to clipboard
fix: prevents fastify-compress from trying to work with something it cannot
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 compress function) 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:
- Test that
Responseobjects are not compressed on global hook - Test that objects get serialized normally when using
compress - Test that
Responseobjects are compressed after being serialized to{}with thecompressfunction.
Checklist
- [x] run
npm run testandnpm run benchmark - [x] tests and/or benchmarks are included
- [ ] documentation is changed or added
- [x] commit message and code follows the Developer's Certification of Origin and the Code of conduct
Great work! Can you document this new option?
@mcollina I considered writing something about it, but I don't think this is something that you can really document? It doesn't so much change functionality so much as prevent a messy thrown error. I can add a gotcha or something at the end of the README.md?
@Aeolun yes. There is a new option passed as the config of the plugin, and that should be mentioned in the README.md