Search code examples
javarestcompressionlagom

Handle compression of Lagom's service responses


According to this Lagom doc for Serialization:

Compression, as described here, is only used for persistent events, persistent snapshots and remote messages with the service cluster. It is not used for messages that are serialized in the external API of the service.

I would like to allow handling request headers, like the

Accept-Encoding: gzip, deflate, sdch, br

So, what would be the approach to handle compression of responses generated by Lagom's services to external applications, e.g. Web-App?


Solution

  • Do you want to actually handle this in your service calls, or do you want to handle it generically at a higher level? If you want to handle it at a higher level, then all you need to do is enable Play's gzip filter:

    https://www.playframework.com/documentation/2.6.x/GzipEncoding

    Currently this only supports gzip, but it could be modified to support other compression encodings.