2

I'm building an application on Laravel 8 and hosting the app on AWS lambda. I want to compress the response with gzip to HTTP request. I had interaction with AWS support and they asked me to add headers with 'Content-Encoding' => 'gzip', and also add isBase64Encoded to true. To achieve this I tried finding out the solution over the internet I found out a documentation for Laravel Vapor which handles this perfectly. They made an middleware which adds these attributes:

$response = $next($request);

if (in_array('gzip', $request->getEncodings()) && function_exists('gzencode')) {
    $response->setContent(gzencode($response->getContent(), 9));
    $response->headers->add([
        'Content-Encoding' => 'gzip',
        'X-Vapor-Base64-Encode' => 'True',
    ]);
}
return $response;

My current header looks like:

enter image description here

Since I'm not using Laravel Vapor So I need to put isBase64Encoded into the header:

I tried executing this via:

$response = $next($request);

if (in_array('gzip', $request->getEncodings()) && function_exists('gzencode')) {
    $response->setContent(gzencode($response->getContent(), 9));
    $response->headers->add([
        'Content-Encoding' => 'gzip',
    ]);
    
    $response->isBase64Encoded = true;
    
    dd($response);
}
return $response;

As you can see I'm trying to add attribute by $response->isBase64Encoded = true;, once implemented the header changes to something unexpected:

enter image description here

Also the content is not encoded. Help me out in adding the isBase64Encoded attributes in response

Rubal Gulati
  • 119
  • 1
  • 5

0 Answers0