Automatically gzip large responses
I wonder if Bref could automatically try to gzip the response if it's bigger than the 6MB limit. I gave it a try and at least this approach works for me (removed the Vapor header): https://bannister.me/blog/gzip-compression-on-laravel-vapor/
Since it's already possible via (Laravel) middleware, it's not urgent but maybe a nice addition.
Hey @jaulz, that is interesting! Do you have any numbers on bigger payloads that you are able to return that way?
Yeah, for the one critical response I was dealing with it's a factor of 24 (from 8MB of text to 300KB):
I used this code:
$content = $response->getContent();
$compressedContent = gzencode($content, 9);
$response->setContent($compressedContent);
$response->headers->add([
'Content-Encoding' => 'gzip',
'X-Original-Size' => mb_strlen($content, '8bit'),
'X-Compressed-Size' => mb_strlen($compressedContent, '8bit'),
]);
Now AWS supports response streaming to bypass 6MB limit
- additional cost if you pass 6MB and with a soft limit of 20MB (maybe ampliable on request)
Its supported on NodeJS official runtime but AWS allows to support on custom runtimes too.
Maybe this will be interesting also in combination with gzip encoding, because GZIP works great on text responses but on binary responses maybe not
https://aws.amazon.com/es/blogs/compute/introducing-aws-lambda-response-streaming/ https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html
In my case from 87,6kB to 5,8kB on a simple SF project using GZIP
@kevincerro FYI https://github.com/brefphp/bref/issues/1503