|
1 | 1 | import { Construct } from 'constructs';
|
2 | 2 | import { CfnResponseHeadersPolicy } from './cloudfront.generated';
|
3 |
| -import { Duration, Names, Resource, Token } from '../../core'; |
| 3 | +import { Duration, Names, Resource, Token, withResolved } from '../../core'; |
4 | 4 |
|
5 | 5 | /**
|
6 | 6 | * Represents a response headers policy.
|
@@ -130,6 +130,15 @@ export class ResponseHeadersPolicy extends Resource implements IResponseHeadersP
|
130 | 130 | }
|
131 | 131 |
|
132 | 132 | private _renderCorsConfig(behavior: ResponseHeadersCorsBehavior): CfnResponseHeadersPolicy.CorsConfigProperty {
|
| 133 | + withResolved(behavior.accessControlAllowMethods, (methods) => { |
| 134 | + const allowedMethods = ['GET', 'DELETE', 'HEAD', 'OPTIONS', 'PATCH', 'POST', 'PUT', 'ALL']; |
| 135 | + if (methods.includes('ALL') && methods.length !== 1) { |
| 136 | + throw new Error("accessControlAllowMethods - 'ALL' cannot be combined with specific HTTP methods."); |
| 137 | + } else if (!methods.every((method) => Token.isUnresolved(method) || allowedMethods.includes(method))) { |
| 138 | + throw new Error(`accessControlAllowMethods contains unexpected method name; allowed values: ${allowedMethods.join(', ')}`); |
| 139 | + } |
| 140 | + }); |
| 141 | + |
133 | 142 | return {
|
134 | 143 | accessControlAllowCredentials: behavior.accessControlAllowCredentials,
|
135 | 144 | accessControlAllowHeaders: { items: behavior.accessControlAllowHeaders },
|
@@ -211,6 +220,9 @@ export interface ResponseHeadersCorsBehavior {
|
211 | 220 |
|
212 | 221 | /**
|
213 | 222 | * A list of HTTP methods that CloudFront includes as values for the Access-Control-Allow-Methods HTTP response header.
|
| 223 | + * |
| 224 | + * Allowed methods: `'GET'`, `'DELETE'`, `'HEAD'`, `'OPTIONS'`, `'PATCH'`, `'POST'`, and `'PUT'`. |
| 225 | + * You can specify `['ALL']` to allow all methods. |
214 | 226 | */
|
215 | 227 | readonly accessControlAllowMethods: string[];
|
216 | 228 |
|
|
0 commit comments