Why does CloudFront still strip brotli from the accept-encoding header?

0

I want to dynamically send GZIP or Brotli compressed files back to the user's browser based on the "accept-encoding" header. If it contains "br", I want to send Brotli. If it does not, like for IE11, I want to send GZIP. Additionally, I want to cache in CloudFront based on the "Accept-Encoding" header.

I set up a POC on my personal account to test this out. I have a Cloudfront distribution pointed to an Elastic Beanstalk Node/Express web application. When I hit the Elastic Beanstalk Node/Express application, it properly receives the accept-encoding header values as "gzip, deflate, br". When I access it through CloudFront, it appears to be stripping the header, so I only get "gzip". As such, my Elastic Beanstalk application has no way of knowing that the request supports brotli. And of course additionally, this means the accept-encoding has no value.

Edit- I edited this question as I found the answer.

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/ServingCompressedFiles.html

Answer is here:
"CloudFront can compress some types of files for you (see File Types that CloudFront Compresses), by using gzip. But if you want to compress other file types, or if you want to use a compression algorithm that isn’t gzip, such as brotli, you can compress the files on your own server, and then serve the files by using CloudFront.

To use CloudFront to serve a file with a compression algorithm that isn’t gzip, set up CloudFront to cache based on the Accept-Encoding header. When you do this, CloudFront does not make any changes to the Accept-Encoding header and your origin can return an appropriate compressed file for the viewer.

When your origin returns a compressed file to CloudFront, include a Content-Encoding header to indicate to CloudFront that the file is already compressed. Then CloudFront simply returns the compressed file to the viewer."

Ensure to whitelist the "accept-encoding" header to stop CloudFront from modifying the header.

Edited by: JPress on Jun 18, 2019 7:44 PM

JPress
asked 5 years ago1114 views
1 Answer
0

We've just announced Brotli support in CloudFront:
https://aws.amazon.com/about-aws/whats-new/2020/09/cloudfront-brotli-compression/

CloudFront now includes 'br' in the normalized 'Accept-Encoding' header before forwarding it to your origin. You no longer need to whitelist the 'Accept-Encoding' header to enable Brotli origin compression. The developer guide has been updated to describe this behavior in depth:
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/ServingCompressedFiles.html

AWS
answered 4 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions