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
질문됨 5년 전1126회 조회
1개 답변
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
답변함 4년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠