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 that 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 responses 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 that 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 decoding the gzip and deflating the stream to normal JSON for subsequent handlers to process.