Skip to content

Commit

Permalink
fix(cloudfront): actually default 'compress' to true (#3359)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimmy Gaussen authored and rix0rrr committed Sep 18, 2019
1 parent 94e05a7 commit 364fd56
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ export class CloudFrontWebDistribution extends cdk.Construct implements IDistrib
let toReturn = {
allowedMethods: this.METHOD_LOOKUP_MAP[input.allowedMethods || CloudFrontAllowedMethods.GET_HEAD],
cachedMethods: this.METHOD_LOOKUP_MAP[input.cachedMethods || CloudFrontAllowedCachedMethods.GET_HEAD],
compress: input.compress,
compress: input.compress !== false,
defaultTtl: input.defaultTtl && input.defaultTtl.toSeconds(),
forwardedValues: input.forwardedValues || { queryString: false, cookies: { forward: "none" } },
maxTtl: input.maxTtl && input.maxTtl.toSeconds(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"QueryString": false
},
"TargetOriginId": "origin1",
"ViewerProtocolPolicy": "redirect-to-https"
"ViewerProtocolPolicy": "redirect-to-https",
"Compress": true
},
"DefaultRootObject": "index.html",
"Enabled": true,
Expand Down Expand Up @@ -95,7 +96,8 @@
"QueryString": false
},
"TargetOriginId": "origin1",
"ViewerProtocolPolicy": "redirect-to-https"
"ViewerProtocolPolicy": "redirect-to-https",
"Compress": true
},
"DefaultRootObject": "index.html",
"Enabled": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"QueryString": false
},
"TargetOriginId": "origin1",
"ViewerProtocolPolicy": "redirect-to-https"
"ViewerProtocolPolicy": "redirect-to-https",
"Compress": true
},
"DefaultRootObject": "index.html",
"Enabled": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"QueryString": false
},
"TargetOriginId": "origin1",
"ViewerProtocolPolicy": "redirect-to-https"
"ViewerProtocolPolicy": "redirect-to-https",
"Compress": true
},
"DefaultRootObject": "",
"Enabled": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"QueryString": false
},
"TargetOriginId": "origin1",
"ViewerProtocolPolicy": "redirect-to-https"
"ViewerProtocolPolicy": "redirect-to-https",
"Compress": true
},
"DefaultRootObject": "index.html",
"Enabled": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
"Ref": "LambdaVersionFA49E61E"
}
}
]
],
"Compress": true
},
"DefaultRootObject": "index.html",
"Enabled": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"QueryString": false
},
"TargetOriginId": "origin1",
"ViewerProtocolPolicy": "redirect-to-https"
"ViewerProtocolPolicy": "redirect-to-https",
"Compress": true
},
"DefaultRootObject": "index.html",
"Enabled": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"QueryString": false
},
"TargetOriginId": "origin1",
"ViewerProtocolPolicy": "redirect-to-https"
"ViewerProtocolPolicy": "redirect-to-https",
"Compress": true
},
"DefaultRootObject": "index.html",
"Enabled": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"QueryString": false
},
"TargetOriginId": "origin1",
"ViewerProtocolPolicy": "redirect-to-https"
"ViewerProtocolPolicy": "redirect-to-https",
"Compress": true
},
"DefaultRootObject": "index.html",
"Enabled": true,
Expand Down
86 changes: 83 additions & 3 deletions packages/@aws-cdk/aws-cloudfront/test/test.basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export = {
"QueryString": false
},
"TargetOriginId": "origin1",
"ViewerProtocolPolicy": "redirect-to-https"
"ViewerProtocolPolicy": "redirect-to-https",
"Compress": true
},
"DefaultRootObject": "index.html",
"Enabled": true,
Expand Down Expand Up @@ -156,7 +157,8 @@ export = {
"ForwardedValues": {
"QueryString": false,
"Cookies": { "Forward": "none" }
}
},
"Compress": true
},
"Enabled": true,
"IPV6Enabled": true,
Expand Down Expand Up @@ -234,7 +236,8 @@ export = {
},
"TrustedSigners": [
"1234"
]
],
"Compress": true
},
"Enabled": true,
"IPV6Enabled": true,
Expand Down Expand Up @@ -309,7 +312,84 @@ export = {
"ForwardedValues": {
"QueryString": false,
"Cookies": { "Forward": "none" }
},
"Compress": true
},
"Enabled": true,
"IPV6Enabled": true,
"HttpVersion": "http2",
}
}
}
}
});
test.done();
},

'distribution with disabled compression'(test: Test) {
const stack = new cdk.Stack();
const sourceBucket = new s3.Bucket(stack, 'Bucket');

new CloudFrontWebDistribution(stack, 'AnAmazingWebsiteProbably', {
originConfigs: [
{
s3OriginSource: {
s3BucketSource: sourceBucket
},
behaviors: [
{
isDefaultBehavior: true,
compress: false
}
]
}
]
});

expect(stack).toMatch({
"Resources": {
"Bucket83908E77": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain",
},
"AnAmazingWebsiteProbablyCFDistribution47E3983B": {
"Type": "AWS::CloudFront::Distribution",
"Properties": {
"DistributionConfig": {
"DefaultRootObject": "index.html",
"Origins": [
{
"DomainName": {
"Fn::GetAtt": [
"Bucket83908E77",
"RegionalDomainName"
]
},
"Id": "origin1",
"S3OriginConfig": {}
}
],
"ViewerCertificate": {
"CloudFrontDefaultCertificate": true
},
"PriceClass": "PriceClass_100",
"DefaultCacheBehavior": {
"AllowedMethods": [
"GET",
"HEAD"
],
"CachedMethods": [
"GET",
"HEAD"
],
"TargetOriginId": "origin1",
"ViewerProtocolPolicy": "redirect-to-https",
"ForwardedValues": {
"QueryString": false,
"Cookies": { "Forward": "none" }
},
"Compress": false
},
"Enabled": true,
"IPV6Enabled": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"QueryString": false
},
"TargetOriginId": "origin1",
"ViewerProtocolPolicy": "redirect-to-https"
"ViewerProtocolPolicy": "redirect-to-https",
"Compress": true
},
"DefaultRootObject": "index.html",
"Enabled": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@
"QueryString": false
},
"TargetOriginId": "origin1",
"ViewerProtocolPolicy": "redirect-to-https"
"ViewerProtocolPolicy": "redirect-to-https",
"Compress": true
},
"DefaultRootObject": "index.html",
"Enabled": true,
Expand Down

0 comments on commit 364fd56

Please sign in to comment.