fix cache

This commit is contained in:
Mateusz Gruszczyński committed 2026-10-09 11:23:24 +02:00
1 parent 0973129c17
commit cc2910afa9
3 files changed
+23

No files matched your search

+5
View File
@@ -34,6 +34,8 @@ class Response:
self.close_callbacks.append(callback)
def make_conditional(self, request):
# Simulate Werkzeug Response.make_conditional adding Date.
self.headers["Date"] = "Fri, 09 Oct 2026 08:58:26 GMT"
if request.headers.get("If-None-Match") == self.headers.get("ETag"):
self.status_code = 304
return self
@@ -196,6 +198,7 @@ check(resp.headers["Cache-Control"] ==
"proxy TTL and staleness")
check(resp.headers["ETag"] == f'"{content_hash}"', "strong output-body ETag")
check(resp.headers["Content-Length"] == str(len(converted)), "content length")
check("Date" not in resp.headers, "GET leaves Date to Uvicorn (no duplicate)")
check(b"".join(resp.data) == converted, "response bytes")
check(source.closed, "upstream closed after success")
check("Last-Modified" not in resp.headers, "origin validator is not forwarded")
@@ -207,6 +210,7 @@ check(resp.status_code == 304, "client 304 after full body hash")
check("headers" not in called[-1][1], "client validators not forwarded to upstream")
check(source.closed, "conditional upstream closed")
check(resp.headers["ETag"] == f'"{content_hash}"', "304 keeps content validator")
check("Date" not in resp.headers, "304 leaves Date to Uvicorn (no duplicate)")
source = FakeUpstream(b"0.0.0.0 another.test\n", headers={"ETag": '"upstream-pretend"'})
changed = run()
@@ -225,6 +229,7 @@ check(head.status_code == 200, "HEAD status")
check(head.data is None, "HEAD no data iterator")
check(head.headers["ETag"] == f'"{content_hash}"', "GET/HEAD same ETag")
check(head.headers["Content-Length"] == str(len(converted)), "HEAD real content length")
check("Date" not in head.headers, "HEAD leaves Date to Uvicorn (no duplicate)")
source = FakeUpstream(converted)
other = run(args={"url": "https://source.test/list.txt", "ip": "127.0.0.1"})