Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.

0 downloads

dbbasic-object-server/tests/test_html_cache_headers.py
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-server.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-server.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-server.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 signup: the person chooses the password and name on the confirm page 83c7aa6 2 weeks, 5 days ago History
test_html_cache_headers.py · 2.3 KB · 58 lines
1"""Object-served HTML is no-store, so "did you deploy?" has one answer.
2
3These pages are rendered per request and their inline script IS the
4application, yet they shipped with no cache headers at all -- leaving the
5browser's heuristic cache in charge of whether a deploy arrived. Safari's
6heuristics bit for real: a /talk fix was deployed and verified live with
7curl while an iPad kept reproducing the old bug, because the iPad was
8running the old page and there was no way to know.
9
10Deliberately HTML-only: the generative widgets (/style, /list, /form) are
11separate objects with their own content types, and turning off caching
12for every asset on every view is a heavier performance decision than a
13stale-page bug justifies.
14"""
15
16import object_server
17
18
19def normalize(payload):
20 return object_server._normalize_object_response(payload)
21
22
23def header(headers, name):
24 return [v for k, v in headers if k.lower() == name]
25
26
27def test_an_html_page_object_is_no_store():
28 _, headers, _ = normalize({"content_type": "text/html; charset=utf-8",
29 "body": "<h1>page</h1>"})
30 assert header(headers, "cache-control") == ["no-store"]
31
32
33def test_a_bare_string_page_is_no_store():
34 _, headers, _ = normalize("bare html")
35 assert header(headers, "cache-control") == ["no-store"]
36
37
38def test_json_and_other_content_types_are_untouched():
39 for payload in ({"content_type": "application/json", "body": "{}"},
40 {"content_type": "text/css", "body": "body{}"},
41 {"content_type": "application/javascript", "body": ";"},
42 {"ok": True}):
43 _, headers, _ = normalize(payload)
44 assert header(headers, "cache-control") == [], payload
45
46
47def test_the_tuple_form_keeps_full_header_control():
48 """An object that writes its own headers is respected -- including
49 choosing to cache."""
50 _, headers, _ = normalize((200, [("content-type", "text/html"),
51 ("cache-control", "max-age=60")], b"x"))
52 assert header(headers, "cache-control") == ["max-age=60"]
53
54
55def test_content_type_parameters_do_not_dodge_the_rule():
56 _, headers, _ = normalize({"content_type": "TEXT/HTML; charset=utf-8",
57 "body": "x"})
58 assert header(headers, "cache-control") == ["no-store"]