Skip to content

Commit a01b81a

Browse files
committed
Update docs.rs to use cache/origin-request policies, forward User-Agent header
1 parent d1881fa commit a01b81a

File tree

1 file changed

+51
-16
lines changed

1 file changed

+51
-16
lines changed

terraform/docs-rs/cloudfront.tf

+51-16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,55 @@ module "certificate" {
1818
]
1919
}
2020

21+
resource "aws_cloudfront_cache_policy" "docs_rs" {
22+
name = "docs-rs"
23+
24+
default_ttl = 31536000 // 1 year
25+
min_ttl = 0
26+
max_ttl = 31536000 // 1 year
27+
28+
parameters_in_cache_key_and_forwarded_to_origin {
29+
headers_config {
30+
header_behavior = "whitelist"
31+
headers {
32+
items = [
33+
// Allow detecting HTTPS from the webapp
34+
"CloudFront-Forwarded-Proto",
35+
// Allow detecting the domain name from the webapp
36+
"Host",
37+
]
38+
}
39+
}
40+
41+
query_strings_config {
42+
query_string_behavior = "all"
43+
}
44+
45+
cookies_config {
46+
cookie_behavior = "none"
47+
}
48+
}
49+
}
50+
51+
resource "aws_cloudfront_origin_request_policy" "docs_rs" {
52+
name = "docs-rs"
53+
54+
headers_config {
55+
header_behavior = "whitelist"
56+
headers {
57+
items = ["User-Agent"]
58+
}
59+
}
60+
61+
query_strings_config {
62+
query_strings_behavior = "all"
63+
}
64+
65+
cookies_config {
66+
cookie_behavior = "none"
67+
}
68+
}
69+
2170
resource "aws_cloudfront_distribution" "webapp" {
2271
comment = local.domain_name
2372

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

44-
default_ttl = 31536000 // 1 year
45-
min_ttl = 0
46-
max_ttl = 31536000 // 1 year
47-
48-
forwarded_values {
49-
headers = [
50-
// Allow detecting HTTPS from the webapp
51-
"CloudFront-Forwarded-Proto",
52-
// Allow detecting the domain name from the webapp
53-
"Host",
54-
]
55-
query_string = true
56-
cookies {
57-
forward = "none"
58-
}
59-
}
93+
cache_policy_id = aws_cloudfront_cache_policy.docs_rs.id
94+
origin_request_policy_id = aws_cloudfront_origin_request_policy.docs_rs.id
6095
}
6196

6297
origin {

0 commit comments

Comments
 (0)