Skip to content

Commit 1e147be

Browse files
authored
Merge pull request #7 from danielcondemarin/configurable-http-methods
add configurable allowed http methods for cache behaviors
2 parents 9ade1f1 + 7c0658c commit 1e147be

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ distribution:
7272
pathPatterns:
7373
/static/images: # route any /static/images requests to https://my-assets.com
7474
ttl: 10
75+
allowedHttpMethods: ['GET', 'HEAD'] # optional
7576
```
7677
7778
#### Lambda@Edge

__tests__/__snapshots__/origin-with-path-pattern.test.js.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ Object {
2121
"Items": Array [
2222
"GET",
2323
"HEAD",
24+
"POST",
2425
],
25-
"Quantity": 2,
26+
"Quantity": 3,
2627
},
2728
"Compress": true,
2829
"DefaultTTL": 10,

__tests__/origin-with-path-pattern.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ describe('Input origin with path pattern', () => {
2828
url: 'https://exampleorigin.com',
2929
pathPatterns: {
3030
'/some/path': {
31-
ttl: 10
31+
ttl: 10,
32+
allowedHttpMethods: ['GET', 'HEAD', 'POST']
3233
}
3334
}
3435
}

lib/getCacheBehavior.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = (pathPattern, pathPatternConfig, originId) => {
2-
const { ttl } = pathPatternConfig
2+
const { ttl, allowedHttpMethods } = pathPatternConfig
3+
const allowedMethods = allowedHttpMethods || ['GET', 'HEAD']
34

45
return {
56
ForwardedValues: {
@@ -25,8 +26,8 @@ module.exports = (pathPattern, pathPatternConfig, originId) => {
2526
},
2627
ViewerProtocolPolicy: 'https-only',
2728
AllowedMethods: {
28-
Quantity: 2,
29-
Items: ['GET', 'HEAD'],
29+
Quantity: allowedMethods.length,
30+
Items: allowedMethods,
3031
CachedMethods: {
3132
Items: ['GET', 'HEAD'],
3233
Quantity: 2

0 commit comments

Comments
 (0)