Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add the "Accept-Encoding" header to my CloudFront distribution?

I opened the CloudFront Dashboard and clicked on the distribution ID, then clicked on the Origin tab and clicked, selected the default origin and then clicked on Edit. Tried to add "Accept-Encoding" in the 'Header Name' under Custom Origin Headers and set its value as "gzip", but it shows the following error:

com.amazonaws.services.cloudfront.model.InvalidArgumentException: The parameter HeaderValue for Accept-Encoding is not empty. (Service: AmazonCloudFront; Status Code: 400; Error Code: InvalidArgument; Request ID: 05685bb6-ca02-11e7-8a62-0b7037d34a58)

What can be done to enable gzip compression through CloudFront?

like image 649
Codecraker Avatar asked Mar 08 '23 14:03

Codecraker


1 Answers

You can not configure CloudFront to cache based on Accept-Encoding header. Quote from aws docs:

You can configure CloudFront to cache based on the value of any request header except the following:

  • Accept-Encoding,
  • Connection,
  • ...

However, you can configure CloudFront to compress supported file types. In CloudFront console "Compress objects automatically" select Yes.

Note: Only files that have a size be between 1,000 and 10,000,000 bytes are compressed. When you use S3 or any other custom origin, CloudFront must get the response with a Content-Length header so it can determine whether the size of the file is in the range that CloudFront compresses. If you are using S3, go to CORS configurations and add the Content-Length header to the list of allowed headers.

If you want your origin to compress files, settings depend on the server you have running on that origin. Server should be set up to serve gzip-ed content to CloudFront with Content-Encoding: gzip header, so it won't be compressed by CloudFront. These are basic guidelines, but exact setting depends on your concrete configuration.

like image 184
Braca Avatar answered Mar 11 '23 01:03

Braca