Skip to content

Commit 7cfb59b

Browse files
authored
Add AuTest and Doc for DELETE method (#12883)
* Add AuTest and Doc for DELETE method * Fix include path
1 parent 8def184 commit 7cfb59b

3 files changed

Lines changed: 213 additions & 0 deletions

File tree

doc/admin-guide/storage/index.en.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
specific language governing permissions and limitations
1616
under the License.
1717
18+
.. include:: ../../common.defs
19+
1820
.. _admin-cache-storage:
1921

2022
Cache Storage
@@ -312,6 +314,27 @@ the object. The next request for that object will result in a fresh copy of the
312314
object fetched. Users may still see the old (removed) content if it was cached by
313315
intermediary caches or by the end-users' web browser.
314316

317+
Conditional Cache Invalidation on DELETE Requests
318+
=================================================
319+
320+
In compliance with :rfc:`9111` Section 4.4 "Invalidating Stored Responses", |TS|
321+
automatically invalidates cached responses when it receives a **successful**
322+
(non-error, i.e., 2xx or 3xx status code) response to a ``DELETE`` request for the same URL.
323+
This behavior ensures cache consistency when resources are deleted at the origin server.
324+
325+
This means:
326+
327+
- If a ``DELETE`` request to the origin server returns a success response
328+
(e.g., ``200 OK``, ``204 No Content``), the cached object for that URL is invalidated.
329+
- If the ``DELETE`` request returns an error response (e.g., ``404 Not Found``,
330+
``405 Method Not Allowed``), the cached object remains unchanged.
331+
332+
.. note::
333+
334+
This automatic invalidation differs from the ``PURGE`` method, which is a |TS| specific
335+
mechanism for explicit cache removal. The ``DELETE`` method invalidation follows standard
336+
HTTP semantics and requires the request to be forwarded to the origin server.
337+
315338
Pushing an Object into the Cache
316339
================================
317340

tests/gold_tests/cache/cache-request-method.test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@
3232

3333
# Verify correct HEAD response handling with cached GET response
3434
Test.ATSReplayTest(replay_file="replay/head_with_get_cached.replay.yaml")
35+
36+
# Verify DELETE request handling - RFC 9111 4.4. Invalidating Stored Responses
37+
Test.ATSReplayTest(replay_file="replay/delete_cached.replay.yaml")
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
meta:
18+
version: "1.0"
19+
20+
# Configuration section for autest integration
21+
autest:
22+
description: 'Verify DELETE method handling'
23+
24+
dns:
25+
name: 'dns-delete'
26+
27+
server:
28+
name: 'server-delete'
29+
30+
client:
31+
name: 'client-delete'
32+
33+
ats:
34+
name: 'ts-cache-delete'
35+
process_config:
36+
enable_cache: true
37+
38+
records_config:
39+
proxy.config.diags.debug.enabled: 1
40+
proxy.config.diags.debug.tags: 'http.*|cache.*'
41+
proxy.config.http.insert_age_in_response: 0
42+
43+
remap_config:
44+
- from: "http://example.com/"
45+
to: "http://backend.example.com:{SERVER_HTTP_PORT}/"
46+
47+
sessions:
48+
- transactions:
49+
50+
# Populate the cache with a response to a GET request.
51+
- client-request:
52+
method: "GET"
53+
version: "1.1"
54+
url: /some/path
55+
headers:
56+
fields:
57+
- [ Host, example.com ]
58+
- [ uuid, 1 ]
59+
60+
server-response:
61+
status: 200
62+
reason: OK
63+
headers:
64+
fields:
65+
- [ Content-Length, 16 ]
66+
- [ Cache-Control, max-age=300 ]
67+
- [ X-Response, first_get_response ]
68+
69+
proxy-response:
70+
status: 200
71+
72+
# Verify that we reply to the request out of the cache.
73+
- client-request:
74+
method: "GET"
75+
version: "1.1"
76+
url: /some/path
77+
headers:
78+
fields:
79+
- [ Host, example.com ]
80+
- [ uuid, 2 ]
81+
82+
# Add a delay so ATS has time to finish any caching IO for the previous transaction.
83+
delay: 100ms
84+
85+
# The request should be served out of cache, so this 403 should not be
86+
# received.
87+
server-response:
88+
status: 403
89+
reason: Forbidden
90+
91+
# ATS should serve the cached 200 response.
92+
proxy-response:
93+
status: 200
94+
headers:
95+
fields:
96+
- [ X-Response, { value: first_get_response, as: equal} ]
97+
98+
# Verify that we do NOT purge cache if origin returns error response for DELETE request
99+
- client-request:
100+
method: "DELETE"
101+
version: "1.1"
102+
url: /some/path
103+
headers:
104+
fields:
105+
- [ Host, example.com ]
106+
- [ uuid, 3 ]
107+
108+
# DELETE request is not allowed
109+
server-response:
110+
status: 405
111+
reason: Method Not Allowed
112+
113+
# ATS should forward the response from origin server
114+
proxy-response:
115+
status: 405
116+
reason: Method Not Allowed
117+
118+
- client-request:
119+
method: "GET"
120+
version: "1.1"
121+
url: /some/path
122+
headers:
123+
fields:
124+
- [ Host, example.com ]
125+
- [ uuid, 4 ]
126+
127+
# The request should be served out of cache, so this 403 should not be
128+
# received.
129+
server-response:
130+
status: 403
131+
reason: Forbidden
132+
133+
# ATS should serve the cached 200 response.
134+
proxy-response:
135+
status: 200
136+
headers:
137+
fields:
138+
- [ X-Response, { value: first_get_response, as: equal} ]
139+
140+
# Verify that we "purge" cache if origin returns non-error response for DELETE request
141+
- client-request:
142+
method: "DELETE"
143+
version: "1.1"
144+
url: /some/path
145+
headers:
146+
fields:
147+
- [ Host, example.com ]
148+
- [ uuid, 5 ]
149+
150+
# DELETE request is accepted
151+
server-response:
152+
status: 204
153+
reason: No Content
154+
155+
# ATS should forward the response from origin server
156+
proxy-response:
157+
status: 204
158+
reason: No Content
159+
160+
# Verify that we cache is purged by DELETE request and returns cache miss
161+
- client-request:
162+
method: "GET"
163+
version: "1.1"
164+
url: /some/path
165+
headers:
166+
fields:
167+
- [ Host, example.com ]
168+
- [ uuid, 6 ]
169+
170+
# Add a delay so ATS has time to finish any caching IO for the previous transaction.
171+
delay: 100ms
172+
173+
server-response:
174+
status: 200
175+
reason: OK
176+
headers:
177+
fields:
178+
- [ Content-Length, 32 ]
179+
- [ Cache-Control, max-age=300 ]
180+
- [ X-Response, second_get_response ]
181+
182+
# ATS should serve the 200 response.
183+
proxy-response:
184+
status: 200
185+
headers:
186+
fields:
187+
- [ X-Response, { value: second_get_response, as: equal} ]

0 commit comments

Comments
 (0)