Skip to content

Commit b2d7dac

Browse files
committed
Fixes Accept-Encoding cache variance behavior
Changes the condition to only ignore Accept-Encoding variance when explicitly set to 1, preserving proper Vary header semantics for the default value of 2. Updates test expectations to reflect correct cache miss behavior when different Accept-Encoding variants are requested, ensuring each encoding type gets its own cache entry with appropriate Content-Encoding headers.
1 parent c7c04b1 commit b2d7dac

File tree

3 files changed

+68
-28
lines changed

3 files changed

+68
-28
lines changed

src/iocore/cache/HttpTransactCache.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,11 @@ HttpTransactCache::CalcVariability(const HttpConfigAccessor *http_config_params,
12441244

12451245
// Disable Vary mismatch checking for Accept-Encoding. This is only safe to
12461246
// set if you are promising to fix any Accept-Encoding/Content-Encoding mismatches.
1247-
if (http_config_params->get_ignore_accept_encoding_mismatch() &&
1247+
// Only suppress variability checks when the operator explicitly set
1248+
// proxy.config.http.cache.ignore_accept_encoding_mismatch to 1. The
1249+
// documented default value of 2 should continue to enforce Vary header
1250+
// semantics whenever the origin sends one.
1251+
if ((http_config_params->get_ignore_accept_encoding_mismatch() == 1) &&
12481252
!strcasecmp(const_cast<char *>(field->str), "Accept-Encoding")) {
12491253
continue;
12501254
}

tests/gold_tests/headers/normalized_ae_match_vary_cache.test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,37 @@
3131
replay_file = "replays/normalized_ae_varied_transactions.replay.yaml"
3232
server = Test.MakeVerifierServerProcess("server", replay_file)
3333

34+
# Verify that cache hit requests never reach the server
35+
# Case 2 (normalize_ae:1) cache hits
36+
server.Streams.stdout += Testers.ExcludesExpression(
37+
"uuid: 12", "Verify empty Accept-Encoding (uuid 12) is a cache hit and doesn't reach the server.")
38+
server.Streams.stdout += Testers.ExcludesExpression(
39+
"uuid: 13", "Verify deflate request (uuid 13) is a cache hit and doesn't reach the server.")
40+
server.Streams.stdout += Testers.ExcludesExpression(
41+
"uuid: 14", "Verify br,compress request (uuid 14) is a cache hit and doesn't reach the server.")
42+
server.Streams.stdout += Testers.ExcludesExpression(
43+
"uuid: 16", "Verify br,compress,gzip request (uuid 16) is a cache hit and doesn't reach the server.")
44+
# Case 3 (normalize_ae:2) cache hits
45+
server.Streams.stdout += Testers.ExcludesExpression(
46+
"uuid: 22", "Verify empty Accept-Encoding (uuid 22) is a cache hit and doesn't reach the server.")
47+
server.Streams.stdout += Testers.ExcludesExpression(
48+
"uuid: 23", "Verify deflate request (uuid 23) is a cache hit and doesn't reach the server.")
49+
server.Streams.stdout += Testers.ExcludesExpression(
50+
"uuid: 26", "Verify br,compress,gzip request (uuid 26) is a cache hit and doesn't reach the server.")
51+
server.Streams.stdout += Testers.ExcludesExpression(
52+
"uuid: 27", "Verify compress,gzip request (uuid 27) is a cache hit and doesn't reach the server.")
53+
# Case 4 (normalize_ae:3) cache hits
54+
server.Streams.stdout += Testers.ExcludesExpression(
55+
"uuid: 32", "Verify empty Accept-Encoding (uuid 32) is a cache hit and doesn't reach the server.")
56+
server.Streams.stdout += Testers.ExcludesExpression(
57+
"uuid: 33", "Verify deflate request (uuid 33) is a cache hit and doesn't reach the server.")
58+
server.Streams.stdout += Testers.ExcludesExpression(
59+
"uuid: 37", "Verify compress,gzip request (uuid 37) is a cache hit and doesn't reach the server.")
60+
server.Streams.stdout += Testers.ExcludesExpression(
61+
"uuid: 38", "Verify br;q=1.1 request (uuid 38) is a cache hit and doesn't reach the server.")
62+
server.Streams.stdout += Testers.ExcludesExpression(
63+
"uuid: 39", "Verify br,gzip;q=0.8 request (uuid 39) is a cache hit and doesn't reach the server.")
64+
3465
ts = Test.MakeATSProcess("ts", enable_cache=True)
3566
ts.Disk.remap_config.AddLine(
3667
f"map http://www.ae-0.com http://127.0.0.1:{server.Variables.http_port}" +

tests/gold_tests/headers/replays/normalized_ae_varied_transactions.replay.yaml

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ sessions:
9696
- [ X-Response-Identifier, { value: Empty-Accept-Encoding, as: equal } ]
9797
- [ X-Cache, { value: miss, as: equal } ]
9898

99-
# Accept-Encoding header deflate would match the alternate of empty Accept-Encoding header
99+
# request deflate Accept-Encoding when origin lacks that variant
100100
- client-request:
101101
method: "GET"
102102
version: "1.1"
@@ -113,13 +113,12 @@ sessions:
113113
<<: *404_response
114114

115115
proxy-response:
116-
status: 200
116+
status: 404
117117
headers:
118118
fields:
119-
- [ X-Response-Identifier, { value: Empty-Accept-Encoding, as: equal } ]
120-
- [ X-Cache, { value: hit-fresh, as: equal } ]
119+
- [ X-Cache, { value: miss, as: equal } ]
121120

122-
# Accept-Encoding header br, compress would match the alternate of empty Accept-Encoding header
121+
# load an alternate of br Accept-Encoding header
123122
- client-request:
124123
method: "GET"
125124
version: "1.1"
@@ -133,14 +132,23 @@ sessions:
133132
delay: 100ms
134133

135134
server-response:
136-
<<: *404_response
135+
status: 200
136+
reason: OK
137+
headers:
138+
fields:
139+
- [ Transfer-Encoding, chunked ]
140+
- [ Cache-Control, max-age=300 ]
141+
- [ Content-Encoding, br ]
142+
- [ Vary, Accept-Encoding ]
143+
- [ Connection, close ]
144+
- [ X-Response-Identifier, Br-Accept-Encoding ]
137145

138146
proxy-response:
139147
status: 200
140148
headers:
141149
fields:
142-
- [ X-Response-Identifier, { value: Empty-Accept-Encoding, as: equal } ]
143-
- [ X-Cache, { value: hit-fresh, as: equal } ]
150+
- [ X-Response-Identifier, { value: Br-Accept-Encoding, as: equal } ]
151+
- [ X-Cache, { value: miss, as: equal } ]
144152

145153
# load an alternate of gzip Accept-Encoding header
146154
- client-request:
@@ -176,7 +184,7 @@ sessions:
176184
- [ X-Response-Identifier, { value: Gzip-Accept-Encoding, as: equal } ]
177185
- [ X-Cache, { value: miss, as: equal } ]
178186

179-
# Accept-Encoding header br, compress, gzip would match the alternate of gzip Accept-Encoding header
187+
# load an alternate of br Accept-Encoding header
180188
- client-request:
181189
method: "GET"
182190
version: "1.1"
@@ -190,14 +198,23 @@ sessions:
190198
delay: 100ms
191199

192200
server-response:
193-
<<: *404_response
201+
status: 200
202+
reason: OK
203+
headers:
204+
fields:
205+
- [ Transfer-Encoding, chunked ]
206+
- [ Cache-Control, max-age=300 ]
207+
- [ Content-Encoding, br ]
208+
- [ Vary, Accept-Encoding ]
209+
- [ Connection, close ]
210+
- [ X-Response-Identifier, Br-Accept-Encoding ]
194211

195212
proxy-response:
196213
status: 200
197214
headers:
198215
fields:
199-
- [ X-Response-Identifier, { value: Gzip-Accept-Encoding, as: equal } ]
200-
- [ X-Cache, { value: hit-fresh, as: equal } ]
216+
- [ X-Response-Identifier, { value: Br-Accept-Encoding, as: equal } ]
217+
- [ X-Cache, { value: miss, as: equal } ]
201218

202219

203220
# Case 2 proxy.config.http.normalize_ae:1
@@ -699,10 +716,6 @@ sessions:
699716
- [ X-Response-Identifier, { value: Gzip-Accept-Encoding, as: equal } ]
700717
- [ X-Cache, { value: miss, as: equal } ]
701718

702-
# NOTICE: This case should load an alternate of br, gzip Accept-Encoding header.
703-
# However, due to the implementation of calculate_quality_of_match(),
704-
# ATS matches the alternate of gzip Accept-Encoding header.
705-
# The result is DIFFERENT from the description of proxy.config.http.normalize_ae: 3
706719
- client-request:
707720
method: "GET"
708721
version: "1.1"
@@ -733,10 +746,8 @@ sessions:
733746
status: 200
734747
headers:
735748
fields:
736-
# - [ X-Response-Identifier, { value: Br-Gzip-Accept-Encoding, as: equal } ]
737-
# - [ X-Cache, { value: miss, as: equal } ]
738-
- [ X-Response-Identifier, { value: Gzip-Accept-Encoding, as: equal } ]
739-
- [ X-Cache, { value: hit-fresh, as: equal } ]
749+
- [ X-Response-Identifier, { value: Br-Gzip-Accept-Encoding, as: equal } ]
750+
- [ X-Cache, { value: miss, as: equal } ]
740751

741752
# Accept-Encoding header compress, gzip would match the alternate of gzip Accept-Encoding header
742753
- client-request:
@@ -784,11 +795,6 @@ sessions:
784795
- [ X-Response-Identifier, { value: Br-Accept-Encoding, as: equal } ]
785796
- [ X-Cache, { value: hit-fresh, as: equal } ]
786797

787-
# NOTICE: This case should make Accept-Encoding header br, gzip;q=0.8 match
788-
# the alternate of br, gzip Accept-Encoding header.
789-
# However, due to the implementation of calculate_quality_of_match(),
790-
# ATS matches the alternate of gzip Accept-Encoding header.
791-
# The result is DIFFERENT from the description of proxy.config.http.normalize_ae: 3
792798
- client-request:
793799
method: "GET"
794800
version: "1.1"
@@ -808,6 +814,5 @@ sessions:
808814
status: 200
809815
headers:
810816
fields:
811-
# - [ X-Response-Identifier, { value: Br-Gzip-Accept-Encoding, as: equal } ]
812-
- [ X-Response-Identifier, { value: Gzip-Accept-Encoding, as: equal } ]
817+
- [ X-Response-Identifier, { value: Br-Gzip-Accept-Encoding, as: equal } ]
813818
- [ X-Cache, { value: hit-fresh, as: equal } ]

0 commit comments

Comments
 (0)