-
-
Notifications
You must be signed in to change notification settings - Fork 36
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the feature has not already been requested
🚀 Feature Proposal
Currently, the only way to specify that the body is binary (ie.: encoded in base64) is by reading the Content-Type and match it with the binaryMimeTypes option. For those cases, the library will respond with the body in base64 perfectly.
But there are cases in which, the response is a text mime type (like application/json) but the body may be encoded in gzip or brotli (compressed).
The proposal is to look into the Content-Encoding and treat them as binary if it is filled, here:
Line 113 in abf3167
| const isBase64Encoded = options.binaryMimeTypes.indexOf(contentType) > -1 |
Add an option to enable/disable this check is acceptable.
Motivation
In our scenario, sometimes we treat with "huge" JSON payloads in both request and responses. The request body works fine compressed, but the response does not. Sometimes we face the issue in which the response is a bit huge and AWS Lambda refuses to respond, but we know that compressed it will work fine.
We use @fastify/compress to handle with compressed payloads.
Example
With the proposal, there is nothing to do to make it work.