Skip to content

Commit

Permalink
feat(cloudfront): brotli compression support (#10950)
Browse files Browse the repository at this point in the history
Enable brotli compression support in `CachePolicy`

Closes #10947
----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
AnderEnder committed Oct 20, 2020
1 parent 37dc9d8 commit dd81e77
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-cloudfront/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ const myCachePolicy = new cloudfront.CachePolicy(this, 'myCachePolicy', {
headerBehavior: cloudfront.CacheHeaderBehavior.allowList('X-CustomHeader'),
queryStringBehavior: cloudfront.CacheQueryStringBehavior.denyList('username'),
enableAcceptEncodingGzip: true,
enableAcceptEncodingBrotli: true,
});
new cloudfront.Distribution(this, 'myDistCustomPolicy', {
defaultBehavior: {
Expand Down
7 changes: 7 additions & 0 deletions packages/@aws-cdk/aws-cloudfront/lib/cache-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ export interface CachePolicyProps {
* @default false
*/
readonly enableAcceptEncodingGzip?: boolean;

/**
* Whether to normalize and include the `Accept-Encoding` header in the cache key when the `Accept-Encoding` header is 'br'.
* @default false
*/
readonly enableAcceptEncodingBrotli?: boolean;
}

/**
Expand Down Expand Up @@ -160,6 +166,7 @@ export class CachePolicy extends Resource implements ICachePolicy {
headers: headers.headers,
},
enableAcceptEncodingGzip: props.enableAcceptEncodingGzip ?? false,
enableAcceptEncodingBrotli: props.enableAcceptEncodingBrotli ?? false,
queryStringsConfig: {
queryStringBehavior: queryStrings.behavior,
queryStrings: queryStrings.queryStrings,
Expand Down
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-cloudfront/test/cache-policy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('CachePolicy', () => {
CookieBehavior: 'none',
},
EnableAcceptEncodingGzip: false,
EnableAcceptEncodingBrotli: false,
HeadersConfig: {
HeaderBehavior: 'none',
},
Expand All @@ -55,6 +56,7 @@ describe('CachePolicy', () => {
headerBehavior: CacheHeaderBehavior.allowList('X-CustomHeader'),
queryStringBehavior: CacheQueryStringBehavior.denyList('username'),
enableAcceptEncodingGzip: true,
enableAcceptEncodingBrotli: true,
});

expect(stack).toHaveResource('AWS::CloudFront::CachePolicy', {
Expand All @@ -77,6 +79,7 @@ describe('CachePolicy', () => {
QueryStrings: ['username'],
},
EnableAcceptEncodingGzip: true,
EnableAcceptEncodingBrotli: true,
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"CookieBehavior": "none"
},
"EnableAcceptEncodingGzip": false,
"EnableAcceptEncodingBrotli": false,
"HeadersConfig": {
"HeaderBehavior": "none"
},
Expand Down

0 comments on commit dd81e77

Please sign in to comment.