Skip to content
v2.274.0

CacheHeaderBehavior Class ​

Determines whether any HTTP headers are included in the cache key and automatically included in requests that CloudFront sends to the origin.

Example ​

ts
// Creating a custom cache policy for a Distribution -- all parameters optional
declare const bucketOrigin: origins.S3Origin;
const myCachePolicy = new cloudfront.CachePolicy(this, 'myCachePolicy', {
  cachePolicyName: 'MyPolicy',
  comment: 'A default policy',
  defaultTtl: Duration.days(2),
  minTtl: Duration.minutes(1),
  maxTtl: Duration.days(10),
  cookieBehavior: cloudfront.CacheCookieBehavior.all(),
  headerBehavior: cloudfront.CacheHeaderBehavior.allowList('X-CustomHeader'),
  queryStringBehavior: cloudfront.CacheQueryStringBehavior.denyList('username'),
  enableAcceptEncodingGzip: true,
  enableAcceptEncodingBrotli: true,
});
new cloudfront.Distribution(this, 'myDistCustomPolicy', {
  defaultBehavior: {
    origin: bucketOrigin,
    cachePolicy: myCachePolicy,
  },
});

Properties ​

behaviorstringbehaviorstrbehaviorStringBehaviorstringBehavior*stringrequired#
If no headers will be passed, or an allow list of headers.
headersstring[]headerstyping.List[str]headersList<String>Headersstring[]Headers*[]*string#
The headers for the allow/deny list, if applicable.

Methods ​

allowList(...headers: string[]): CacheHeaderBehavior // chainable@staticmethod def allow_list(headers: str) -> CacheHeaderBehaviorpublic static CacheHeaderBehavior allowList(String headers)public static CacheHeaderBehavior AllowList(string headers)func AllowList(Headers *string) CacheHeaderBehaviorstatic#
Listed headers are included in the cache key and are automatically included in requests that CloudFront sends to the origin.
none(): CacheHeaderBehavior // chainable@staticmethod def none() -> CacheHeaderBehaviorpublic static CacheHeaderBehavior none()public static CacheHeaderBehavior None()func None() CacheHeaderBehaviorstatic#
HTTP headers are not included in the cache key and are not automatically included in requests that CloudFront sends to the origin.