From 7c0658c0ded0a7727f84be7e689bd357221ebab8 Mon Sep 17 00:00:00 2001 From: danielconde Date: Wed, 18 Sep 2019 21:45:51 +0100 Subject: [PATCH] add configurable allowed http methods for cache behaviors --- README.md | 1 + .../__snapshots__/origin-with-path-pattern.test.js.snap | 3 ++- __tests__/origin-with-path-pattern.test.js | 3 ++- lib/getCacheBehavior.js | 7 ++++--- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6c0dd1e..9f085e0 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ distribution: pathPatterns: /static/images: # route any /static/images requests to https://my-assets.com ttl: 10 + allowedHttpMethods: ['GET', 'HEAD'] # optional ``` #### Lambda@Edge diff --git a/__tests__/__snapshots__/origin-with-path-pattern.test.js.snap b/__tests__/__snapshots__/origin-with-path-pattern.test.js.snap index 3a34a9b..1a93625 100644 --- a/__tests__/__snapshots__/origin-with-path-pattern.test.js.snap +++ b/__tests__/__snapshots__/origin-with-path-pattern.test.js.snap @@ -21,8 +21,9 @@ Object { "Items": Array [ "GET", "HEAD", + "POST", ], - "Quantity": 2, + "Quantity": 3, }, "Compress": true, "DefaultTTL": 10, diff --git a/__tests__/origin-with-path-pattern.test.js b/__tests__/origin-with-path-pattern.test.js index ee64b35..5b0d8bf 100644 --- a/__tests__/origin-with-path-pattern.test.js +++ b/__tests__/origin-with-path-pattern.test.js @@ -28,7 +28,8 @@ describe('Input origin with path pattern', () => { url: 'https://exampleorigin.com', pathPatterns: { '/some/path': { - ttl: 10 + ttl: 10, + allowedHttpMethods: ['GET', 'HEAD', 'POST'] } } } diff --git a/lib/getCacheBehavior.js b/lib/getCacheBehavior.js index 72b9154..064e1d4 100644 --- a/lib/getCacheBehavior.js +++ b/lib/getCacheBehavior.js @@ -1,5 +1,6 @@ module.exports = (pathPattern, pathPatternConfig, originId) => { - const { ttl } = pathPatternConfig + const { ttl, allowedHttpMethods } = pathPatternConfig + const allowedMethods = allowedHttpMethods || ['GET', 'HEAD'] return { ForwardedValues: { @@ -25,8 +26,8 @@ module.exports = (pathPattern, pathPatternConfig, originId) => { }, ViewerProtocolPolicy: 'https-only', AllowedMethods: { - Quantity: 2, - Items: ['GET', 'HEAD'], + Quantity: allowedMethods.length, + Items: allowedMethods, CachedMethods: { Items: ['GET', 'HEAD'], Quantity: 2