Skip to content

Commit 90d2eb3

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 90d2eb3

File tree

2 files changed

+54
-28
lines changed

2 files changed

+54
-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/replays/normalized_ae_varied_transactions.replay.yaml

Lines changed: 49 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+
# load an alternate of deflate Accept-Encoding header
100100
- client-request:
101101
method: "GET"
102102
version: "1.1"
@@ -110,16 +110,25 @@ sessions:
110110
delay: 100ms
111111

112112
server-response:
113-
<<: *404_response
113+
status: 200
114+
reason: OK
115+
headers:
116+
fields:
117+
- [ Transfer-Encoding, chunked ]
118+
- [ Cache-Control, max-age=300 ]
119+
- [ Content-Encoding, deflate ]
120+
- [ Vary, Accept-Encoding ]
121+
- [ Connection, close ]
122+
- [ X-Response-Identifier, Deflate-Accept-Encoding ]
114123

115124
proxy-response:
116125
status: 200
117126
headers:
118127
fields:
119-
- [ X-Response-Identifier, { value: Empty-Accept-Encoding, as: equal } ]
120-
- [ X-Cache, { value: hit-fresh, as: equal } ]
128+
- [ X-Response-Identifier, { value: Deflate-Accept-Encoding, as: equal } ]
129+
- [ X-Cache, { value: miss, as: equal } ]
121130

122-
# Accept-Encoding header br, compress would match the alternate of empty Accept-Encoding header
131+
# load an alternate of br Accept-Encoding header
123132
- client-request:
124133
method: "GET"
125134
version: "1.1"
@@ -133,14 +142,23 @@ sessions:
133142
delay: 100ms
134143

135144
server-response:
136-
<<: *404_response
145+
status: 200
146+
reason: OK
147+
headers:
148+
fields:
149+
- [ Transfer-Encoding, chunked ]
150+
- [ Cache-Control, max-age=300 ]
151+
- [ Content-Encoding, br ]
152+
- [ Vary, Accept-Encoding ]
153+
- [ Connection, close ]
154+
- [ X-Response-Identifier, Br-Accept-Encoding ]
137155

138156
proxy-response:
139157
status: 200
140158
headers:
141159
fields:
142-
- [ X-Response-Identifier, { value: Empty-Accept-Encoding, as: equal } ]
143-
- [ X-Cache, { value: hit-fresh, as: equal } ]
160+
- [ X-Response-Identifier, { value: Br-Accept-Encoding, as: equal } ]
161+
- [ X-Cache, { value: miss, as: equal } ]
144162

145163
# load an alternate of gzip Accept-Encoding header
146164
- client-request:
@@ -162,6 +180,7 @@ sessions:
162180
fields:
163181
- [ Transfer-Encoding, chunked ]
164182
- [ Cache-Control, max-age=300 ]
183+
- [ Content-Encoding, gzip ]
165184
- [ Vary, Accept-Encoding ]
166185
- [ Connection, close ]
167186
- [ X-Response-Identifier, Gzip-Accept-Encoding ]
@@ -176,7 +195,7 @@ sessions:
176195
- [ X-Response-Identifier, { value: Gzip-Accept-Encoding, as: equal } ]
177196
- [ X-Cache, { value: miss, as: equal } ]
178197

179-
# Accept-Encoding header br, compress, gzip would match the alternate of gzip Accept-Encoding header
198+
# load an alternate of br Accept-Encoding header
180199
- client-request:
181200
method: "GET"
182201
version: "1.1"
@@ -190,14 +209,23 @@ sessions:
190209
delay: 100ms
191210

192211
server-response:
193-
<<: *404_response
212+
status: 200
213+
reason: OK
214+
headers:
215+
fields:
216+
- [ Transfer-Encoding, chunked ]
217+
- [ Cache-Control, max-age=300 ]
218+
- [ Content-Encoding, br ]
219+
- [ Vary, Accept-Encoding ]
220+
- [ Connection, close ]
221+
- [ X-Response-Identifier, Br-Accept-Encoding ]
194222

195223
proxy-response:
196224
status: 200
197225
headers:
198226
fields:
199-
- [ X-Response-Identifier, { value: Gzip-Accept-Encoding, as: equal } ]
200-
- [ X-Cache, { value: hit-fresh, as: equal } ]
227+
- [ X-Response-Identifier, { value: Br-Accept-Encoding, as: equal } ]
228+
- [ X-Cache, { value: miss, as: equal } ]
201229

202230

203231
# Case 2 proxy.config.http.normalize_ae:1
@@ -322,6 +350,7 @@ sessions:
322350
fields:
323351
- [ Transfer-Encoding, chunked ]
324352
- [ Cache-Control, max-age=300 ]
353+
- [ Content-Encoding, gzip ]
325354
- [ Vary, Accept-Encoding ]
326355
- [ Connection, close ]
327356
- [ X-Response-Identifier, Gzip-Accept-Encoding ]
@@ -458,6 +487,7 @@ sessions:
458487
fields:
459488
- [ Transfer-Encoding, chunked ]
460489
- [ Cache-Control, max-age=300 ]
490+
- [ Content-Encoding, br ]
461491
- [ Vary, Accept-Encoding ]
462492
- [ Connection, close ]
463493
- [ X-Response-Identifier, Br-Accept-Encoding ]
@@ -492,6 +522,7 @@ sessions:
492522
fields:
493523
- [ Transfer-Encoding, chunked ]
494524
- [ Cache-Control, max-age=300 ]
525+
- [ Content-Encoding, gzip ]
495526
- [ Vary, Accept-Encoding ]
496527
- [ Connection, close ]
497528
- [ X-Response-Identifier, Gzip-Accept-Encoding ]
@@ -651,6 +682,7 @@ sessions:
651682
fields:
652683
- [ Transfer-Encoding, chunked ]
653684
- [ Cache-Control, max-age=300 ]
685+
- [ Content-Encoding, br ]
654686
- [ Vary, Accept-Encoding ]
655687
- [ Connection, close ]
656688
- [ X-Response-Identifier, Br-Accept-Encoding ]
@@ -686,6 +718,7 @@ sessions:
686718
- [ Transfer-Encoding, chunked ]
687719
- [ Cache-Control, max-age=300 ]
688720
- [ Vary, Accept-Encoding ]
721+
- [ Content-Encoding, gzip ]
689722
- [ Connection, close ]
690723
- [ X-Response-Identifier, Gzip-Accept-Encoding ]
691724
content:
@@ -699,10 +732,6 @@ sessions:
699732
- [ X-Response-Identifier, { value: Gzip-Accept-Encoding, as: equal } ]
700733
- [ X-Cache, { value: miss, as: equal } ]
701734

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
706735
- client-request:
707736
method: "GET"
708737
version: "1.1"
@@ -722,6 +751,7 @@ sessions:
722751
fields:
723752
- [ Transfer-Encoding, chunked ]
724753
- [ Cache-Control, max-age=300 ]
754+
- [ Content-Encoding, "br, gzip" ]
725755
- [ Vary, Accept-Encoding ]
726756
- [ Connection, close ]
727757
- [ X-Response-Identifier, Br-Gzip-Accept-Encoding ]
@@ -733,10 +763,8 @@ sessions:
733763
status: 200
734764
headers:
735765
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 } ]
766+
- [ X-Response-Identifier, { value: Br-Gzip-Accept-Encoding, as: equal } ]
767+
- [ X-Cache, { value: miss, as: equal } ]
740768

741769
# Accept-Encoding header compress, gzip would match the alternate of gzip Accept-Encoding header
742770
- client-request:
@@ -784,11 +812,6 @@ sessions:
784812
- [ X-Response-Identifier, { value: Br-Accept-Encoding, as: equal } ]
785813
- [ X-Cache, { value: hit-fresh, as: equal } ]
786814

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
792815
- client-request:
793816
method: "GET"
794817
version: "1.1"
@@ -808,6 +831,5 @@ sessions:
808831
status: 200
809832
headers:
810833
fields:
811-
# - [ X-Response-Identifier, { value: Br-Gzip-Accept-Encoding, as: equal } ]
812-
- [ X-Response-Identifier, { value: Gzip-Accept-Encoding, as: equal } ]
834+
- [ X-Response-Identifier, { value: Br-Gzip-Accept-Encoding, as: equal } ]
813835
- [ X-Cache, { value: hit-fresh, as: equal } ]

0 commit comments

Comments
 (0)