Skip to content

Commit c6ab33d

Browse files
committed
HEAD updates
For #102.
1 parent c0ad544 commit c6ab33d

File tree

3 files changed

+112
-2
lines changed

3 files changed

+112
-2
lines changed

lib/templates.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export const stale = makeTemplate({
2222

2323
export const becomeStale = makeTemplate({
2424
response_headers: [
25-
['Cache-Control', 'max-age=2']
25+
['Cache-Control', 'max-age=2'],
26+
['Template-A', '1']
2627
],
2728
setup: true,
2829
pause_after: true

tests/index.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import conditionalLm from './conditional-lm.mjs'
1616
import conditionalEtag from './conditional-etag.mjs'
1717
import headers from './headers.mjs'
1818
import update304 from './update304.mjs'
19+
import updateHead from './updateHead.mjs'
1920
import invalidation from './invalidation.mjs'
2021
import partial from './partial.mjs'
2122
import other from './other.mjs'
2223

23-
export default [ccFreshness, ccParse, ageParse, expires, expiresParse, ccResponse, stale, heuristic, methods, statuses, ccRequest, pragma, vary, varyParse, conditionalLm, conditionalEtag, headers, update304, invalidation, partial, other]
24+
export default [ccFreshness, ccParse, ageParse, expires, expiresParse, ccResponse, stale, heuristic, methods, statuses, ccRequest, pragma, vary, varyParse, conditionalLm, conditionalEtag, headers, update304, updateHead, invalidation, partial, other]

tests/updateHead.mjs

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
2+
import * as templates from '../lib/templates.mjs'
3+
4+
export default
5+
6+
{
7+
name: 'HEAD updates',
8+
id: 'updateHEAD',
9+
description: 'HTTP [specifies](https://httpwg.org/http-core/draft-ietf-httpbis-cache-latest.html#head.effects) that `HEAD` responses should update stored responses under certain conditions.',
10+
tests: [
11+
{
12+
name: 'Does HTTP cache write through a HEAD when stored response is stale?',
13+
id: 'head-writethrough',
14+
kind: 'check',
15+
requests: [
16+
templates.becomeStale({}),
17+
{
18+
request_method: 'HEAD',
19+
expected_method: 'HEAD'
20+
}
21+
]
22+
},
23+
{
24+
name: 'Does HTTP cache preserve stored fields not received in a `200` response to a `HEAD`?',
25+
id: 'head-200-retain',
26+
kind: 'check',
27+
depends_on: ['head-writethrough'],
28+
requests: [
29+
templates.becomeStale({}),
30+
{
31+
request_method: 'HEAD',
32+
expected_method: 'HEAD',
33+
expected_response_headers: [
34+
['Template-A', '1']
35+
]
36+
}
37+
]
38+
},
39+
{
40+
name: 'Does HTTP cache update freshness lifetime recieved in a `200` response to a `HEAD`?',
41+
id: 'head-200-freshness-update',
42+
kind: 'check',
43+
depends_on: ['head-writethrough'],
44+
requests: [
45+
templates.becomeStale({}),
46+
{
47+
request_method: 'HEAD',
48+
expected_method: 'HEAD',
49+
response_headers: [
50+
['Cache-Control', 'max-age=1000']
51+
],
52+
},
53+
{
54+
expected_type: 'cached'
55+
}
56+
]
57+
},
58+
{
59+
name: 'Does HTTP cache update stored fields recieved in a `200` response to a `HEAD`?',
60+
id: 'head-200-update',
61+
kind: 'check',
62+
depends_on: ['head-writethrough', 'head-200-freshness-update'],
63+
requests: [
64+
templates.becomeStale({}),
65+
{
66+
request_method: 'HEAD',
67+
expected_method: 'HEAD',
68+
response_headers: [
69+
['Template-A', '2'],
70+
['Cache-Control', 'max-age=1000']
71+
],
72+
},
73+
{
74+
expected_type: 'cached',
75+
setup_tests: ['expected_type'],
76+
expected_response_headers: [
77+
['Template-A', '2']
78+
]
79+
}
80+
]
81+
},
82+
{
83+
name: 'Does HTTP cache update stored fields recieved in a `410` response to a `HEAD`?',
84+
id: 'head-410-update',
85+
kind: 'check',
86+
depends_on: ['head-writethrough', 'head-200-freshness-update'],
87+
requests: [
88+
templates.becomeStale({}),
89+
{
90+
request_method: 'HEAD',
91+
expected_method: 'HEAD',
92+
response_status: [410, 'Gone'],
93+
response_headers: [
94+
['Template-A', '2'],
95+
['Cache-Control', 'max-age=1000']
96+
],
97+
},
98+
{
99+
expected_type: 'cached',
100+
setup_tests: ['expected_type'],
101+
expected_response_headers: [
102+
['Template-A', '2']
103+
]
104+
}
105+
]
106+
}
107+
]
108+
}

0 commit comments

Comments
 (0)