To reduce bandwidth usage and speed up the delivery, many clients and servers utilize gzip or deflate encoding for large requests or responses.
One of our users built an API receives batch data from iOS, and the request is encoded with gzip. It requires that we have a RequestDecodeHandler before the BodyHandler to decode the gzip stream so that subsequent handlers can handle the request as a normal JSON body.
Sometimes, we might have services that produce big size JSON response to the client, and we might consider encoding the response body with gzip as the majority of browsers support it.
This module contains two middleware handlers one works on the incoming request and the other works on the outgoing response. Usually, there is only one handler should be used by a particular service.
This middleware handler must be wired in the request handler chain before BodyHandler. It looks for the header for encoding and decode the gzip and deflate stream to normal JSON for subseqent handlers to process.