Skip to content

Commit

Permalink
Update docs.rs to use cache/origin-request policies, forward User-Age…
Browse files Browse the repository at this point in the history
…nt header
  • Loading branch information
Nemo157 committed Sep 11, 2023
1 parent d1881fa commit a01b81a
Showing 1 changed file with 51 additions and 16 deletions.
67 changes: 51 additions & 16 deletions terraform/docs-rs/cloudfront.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,55 @@ module "certificate" {
]
}

resource "aws_cloudfront_cache_policy" "docs_rs" {
name = "docs-rs"

default_ttl = 31536000 // 1 year
min_ttl = 0
max_ttl = 31536000 // 1 year

parameters_in_cache_key_and_forwarded_to_origin {
headers_config {
header_behavior = "whitelist"
headers {
items = [
// Allow detecting HTTPS from the webapp
"CloudFront-Forwarded-Proto",
// Allow detecting the domain name from the webapp
"Host",
]
}
}

query_strings_config {
query_string_behavior = "all"
}

cookies_config {
cookie_behavior = "none"
}
}
}

resource "aws_cloudfront_origin_request_policy" "docs_rs" {
name = "docs-rs"

headers_config {
header_behavior = "whitelist"
headers {
items = ["User-Agent"]
}
}

query_strings_config {
query_strings_behavior = "all"
}

cookies_config {
cookie_behavior = "none"
}
}

resource "aws_cloudfront_distribution" "webapp" {
comment = local.domain_name

Expand All @@ -41,22 +90,8 @@ resource "aws_cloudfront_distribution" "webapp" {
compress = true
viewer_protocol_policy = "redirect-to-https"

default_ttl = 31536000 // 1 year
min_ttl = 0
max_ttl = 31536000 // 1 year

forwarded_values {
headers = [
// Allow detecting HTTPS from the webapp
"CloudFront-Forwarded-Proto",
// Allow detecting the domain name from the webapp
"Host",
]
query_string = true
cookies {
forward = "none"
}
}
cache_policy_id = aws_cloudfront_cache_policy.docs_rs.id
origin_request_policy_id = aws_cloudfront_origin_request_policy.docs_rs.id
}

origin {
Expand Down

0 comments on commit a01b81a

Please sign in to comment.