fastify / fastify-compress

Fastify compression utils

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compression should happen after serialization

wedgwood opened this issue · comments

commented

As titled, compression is for string-like or buffer-like variable, so should it happen after serialization at the end of SendEnd?

I'm not sure I've understood your question.
The compression happens after the serialization.

commented

Hi, @delvedor .
It seems not the order. I found the current order is
reply.send() -> hooks.onSend() -> reply._serializer(payload). And compression registered in hooks.onSend. If object (such as {hello: 'world'}) be sent, the object will be compressed first then serialized. How could an object be compressed? Unexpected behavior happens.

No, the order is:

  • the user calls reply.send
  • the hook onSend is triggered
    • fastify-compress hook is executed
      • if the payload is a stream => compress
      • if the payload is a string => compress
      • if the payload is an object => serialize => compress
  • fastify sends the compressed data

If you are not convinced try to write a test (o read ours) :)

commented

Sorry, my fault, I have not review the code carefully. Now I get it. Thx!