Skip to content

Commit c829f37

Browse files
configurable http methods for default cache behavior
1 parent b462f44 commit c829f37

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ distribution:
5252
enabled: true # optional
5353
defaults: # optional
5454
ttl: 15
55+
allowedHttpMethods: ['HEAD', 'GET']
5556
lambda@edge: # added to cloudfront default cache behavior
5657
viewer-request: arn:aws:lambda:us-east-1:123:function:myFunc:version
5758
origins:

__tests__/__snapshots__/custom-url-origin.test.js.snap

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ Object {
2424
},
2525
"Items": Array [
2626
"HEAD",
27+
"DELETE",
28+
"POST",
2729
"GET",
30+
"OPTIONS",
31+
"PUT",
32+
"PATCH",
2833
],
29-
"Quantity": 2,
34+
"Quantity": 7,
3035
},
3136
"Compress": false,
3237
"DefaultTTL": 10,

__tests__/custom-url-origin.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe('Input origin as a custom url', () => {
2424
it('creates distribution with custom url origin and sets defaults', async () => {
2525
await component.default({
2626
defaults: {
27+
allowedHttpMethods: ['HEAD', 'DELETE', 'POST', 'GET', 'OPTIONS', 'PUT', 'PATCH'],
2728
ttl: 10,
2829
'lambda@edge': {
2930
'origin-request': 'arn:aws:lambda:us-east-1:123:function:originRequestFunction'

lib/getDefaultCacheBehavior.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const addLambdaAtEdgeToCacheBehavior = require('./addLambdaAtEdgeToCacheBehavior')
22

33
module.exports = (originId, defaults = {}) => {
4+
const allowedMethods = defaults.allowedHttpMethods || ['HEAD', 'GET']
5+
46
const defaultCacheBehavior = {
57
TargetOriginId: originId,
68
ForwardedValues: {
@@ -25,8 +27,8 @@ module.exports = (originId, defaults = {}) => {
2527
ViewerProtocolPolicy: 'redirect-to-https',
2628
MinTTL: 0,
2729
AllowedMethods: {
28-
Quantity: 2,
29-
Items: ['HEAD', 'GET'],
30+
Quantity: allowedMethods.length,
31+
Items: allowedMethods,
3032
CachedMethods: {
3133
Quantity: 2,
3234
Items: ['HEAD', 'GET']

0 commit comments

Comments
 (0)